代码之家  ›  专栏  ›  技术社区  ›  timmwagener

Angular9/Typescript3.8/Babylon4.1.0-Typescript编译错误-找不到模块react/找不到命名空间JSX

  •  0
  • timmwagener  · 技术社区  · 5 年前

    我目前面临的编译问题 巴比伦4.1.0 在angular9应用程序的上下文中。似乎检查员无法导入内部使用的 "react" 模块。该问题可由 *将@babylon/*依赖项添加到 package.json *添加 import '@babylonjs/inspector'; app.component.ts

    我玩了几个 module target 中的设置 tsconfig.json 但是没有运气。坦白说,我在这里也有点不知所措 npm 应该已经下载了所需的依赖项 react ) . 你知道什么会导致这些问题吗?


    错误日志

    $ 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";
                                   ~~~~~~~
    ...
    

    :

    {
      "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"
      }
    }
    

    :

    {
      "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"
    }
    

    组件.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`);
      }
    }
    
    1 回复  |  直到 5 年前
        1
  •  0
  •   timmwagener    5 年前

    当使用巴比伦版本时 4.0.3 误差不同,其余均同上: (与此相反,巴比伦4.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.
    
        2
  •  0
  •   timmwagener    5 年前

    巴比伦 BabylonJS forum . 基本上:

    • 4.1.0 巴比伦的版本 @types/react @types/react-dom 部门。不知怎么的,在框架需求中迷失了方向。
    • package.json devDependencies 为客户端修复此问题。
    • BabylonJS在未来的版本中可能会有这个修复和deps。将再次添加。
    推荐文章