簡體   English   中英

Angular9/Typescript3.8/Babylon4.1.0 - Typescript 編譯錯誤 - 找不到模塊'react'/找不到命名空間'JSX'

[英]Angular9/Typescript3.8/Babylon4.1.0 - Typescript compilation error - Cannot find module ‘react’/Cannot find namespace ‘JSX’

我目前在 angular9 應用程序的上下文中面臨Babylon4.1.0的編譯問題。 檢查員似乎無法導入內部使用的"react"模塊。 可以通過以下方式重現該問題 * 使用 CLI 創建引導 angular9 應用 * 將 @babylon/* 依賴項添加到package.json * 添加import '@babylonjs/inspector'; app.component.ts

我在tsconfig.json中使用了幾個moduletarget設置,但沒有運氣。 坦率地說,我在這里也有點無能為力,因為我認為npm應該已經下載了所需的依賴項(如react 任何想法可能導致問題?


這是相關文件,但如前所述,這基本上只是一個新引導的准系統 angular9 應用程序。 用於重現問題。 設置幾乎都是出廠默認設置。

錯誤日志

$ npm run start

> angular9-babylon41@0.0.0 start D:\repos\angular9-babylon41
> ng serve


chunk {main} main.js, main.js.map (main) 1.99 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 673 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 12.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 340 kB [initial] [rendered]
Date: 2020-05-31T11:09:34.586Z - Hash: e370845231b8941feaea - Time: 13568ms

ERROR in node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:77:28 - error TS2307: Cannot find module 'react'.

77     import * as React from "react";
                              ~~~~~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:94:19 - error TS2503: Cannot find namespace 'JSX'.

94         render(): JSX.Element | null;
                     ~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:98:28 - error TS2307: Cannot find module 'react'.

98     import * as React from "react";
                              ~~~~~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:108:59 - error TS2503: Cannot find namespace 'JSX'.

108         renderLabel(child: PaneComponent, index: number): JSX.Element;
                                                              ~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:109:19 - error TS2503: Cannot find namespace 'JSX'.

109         render(): JSX.Element;
                      ~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:113:28 - error TS2307: Cannot find module 'react'.

113     import * as React from "react";
                               ~~~~~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:125:26 - error TS2503: Cannot find namespace 'JSX'.

125         renderContent(): JSX.Element | null;
                             ~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:126:19 - error TS2503: Cannot find namespace 'JSX'.

126         render(): JSX.Element;
                      ~~~
node_modules/@babylonjs/inspector/babylon.inspector.module.d.ts:130:28 - error TS2307: Cannot find module 'react'.

130     import * as React from "react";
                               ~~~~~~~
...

package.json

{
  "name": "angular9-babylon41",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.1.9",
    "@angular/common": "~9.1.9",
    "@angular/compiler": "~9.1.9",
    "@angular/core": "~9.1.9",
    "@angular/forms": "~9.1.9",
    "@angular/platform-browser": "~9.1.9",
    "@angular/platform-browser-dynamic": "~9.1.9",
    "@angular/router": "~9.1.9",
    "@babylonjs/core": "^4.1.0",
    "@babylonjs/gui": "^4.1.0",
    "@babylonjs/inspector": "^4.1.0",
    "@babylonjs/loaders": "^4.1.0",
    "@babylonjs/materials": "^4.1.0",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.7",
    "@angular/cli": "~9.1.7",
    "@angular/compiler-cli": "~9.1.9",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "angular9-babylon41": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "preserveSymlinks": true,
            "outputPath": "dist/angular9-babylon41",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular9-babylon41:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "angular9-babylon41:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "angular9-babylon41:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "angular9-babylon41:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "angular9-babylon41:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "angular9-babylon41"
}

app.component.ts

import { Component } from '@angular/core';
import { OnInit } from '@angular/core';

import '@babylonjs/inspector';  // causes compilation error

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
  title = 'angular9-babylon41';

  ngOnInit() {
    console.log(`Test`);
  }
}

該解決方案由BabylonJS核心開發人員提供。 BabylonJS 論壇中。 基本上:

  • 在 BabylonJS 的4.1.0版本中, @types/react@types/react-dom依賴。 不知何故迷失在框架要求中。
  • 將它們手動添加到package.json devDependencies可以為客戶端修復此問題。
  • BabylonJS 可能會在未來的某個版本中修復這個問題,並且 deps. 將再次添加。

使用 Babylon 4.0.3時,錯誤有所不同,其他一切與上述相同:(與此相反,Babylon4.0.3、Angular8 和 TS 3.5 的組合在過去一直有效)

$ npm run start

> angular9-babylon41@0.0.0 start D:\repos\angular9-babylon41
> ng serve


chunk {main} main.js, main.js.map (main) 1.99 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 673 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 12.4 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 340 kB [initial] [rendered]
Date: 2020-05-31T12:17:13.978Z - Hash: e4a4da1571609f68f746 - Time: 14364ms

ERROR in node_modules/@babylonjs/core/Engines/engine.d.ts:8:10 - error TS2303: Circular definition of import alias 'IDisplayChangedEventArgs'.

8 import { IDisplayChangedEventArgs } from "../Engines/engine";
           ~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@babylonjs/core/Engines/engine.d.ts:8:10 - error TS2459: Module '"../Engines/engine"' declares 'IDisplayChangedEventArgs' locally, but it is not exported.

8 import { IDisplayChangedEventArgs } from "../Engines/engine";
           ~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@babylonjs/core/Engines/engine.d.ts:8:10
    8 import { IDisplayChangedEventArgs } from "../Engines/engine";
               ~~~~~~~~~~~~~~~~~~~~~~~~
    'IDisplayChangedEventArgs' is declared here.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM