首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular9 9/Typescript3.8/Babylon4.1.0--类型记录编译错误--找不到模块‘react’/找不到命名空间‘JSX’

问Angular9 9/Typescript3.8/Babylon4.1.0--类型记录编译错误--找不到模块‘react’/找不到命名空间‘JSX’
EN

Stack Overflow用户
提问于 2020-05-31 12:24:11
回答 2查看 4.8K关注 0票数 5

目前,我面临着Babylon4.1.0在angular9应用程序上下文中的编译问题。检查器似乎无法导入内部使用的"react"模块。这个问题可以通过创建一个带有CLI *的引导angular9应用程序来再现,将@巴比伦/*依赖项添加到package.json *将import '@babylonjs/inspector';添加到app.component.ts

我在module和target中玩了几个tsconfig.json设置,但没有运气。坦率地说,我在这里也有点不知所措,因为我假设npm应该已经下载了所需的依赖项(比如react__)。有什么想法可以引起这些问题吗?

下面是相关的文件,但正如前面提到的,这基本上只是一个新引导的、简单的angular9应用程序。为了复制这个问题。设置几乎都是工厂默认设置。

错误日志

代码语言:javascript
复制
$ 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

代码语言:javascript
复制
{
  "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

代码语言:javascript
复制
{
  "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

代码语言:javascript
复制
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

angular.json

代码语言:javascript
复制
{
  "$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

代码语言:javascript
复制
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`);
  }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-19 14:46:59

该解决方案由BabylonJS核心开发人员提供。在BabylonJS论坛里。基本上:

  • 在4.1.0版本的BabylonJS中,@types/react和@types/react-dom deps。不知何故在框架要求中迷失了方向。
  • 将它们手动添加到package.json devDependencies中可以为客户端修复此问题。
  • BabylonJS很可能在将来的某些版本中有这个固定和deps。将再次添加。
票数 7
EN

Stack Overflow用户

发布于 2020-05-31 12:24:47

当使用巴比伦版本4.0.3时,错误是不同的,其他一切都是相同的:(与此相反,Babylon4.0.3、Angular8 &TS3.5的组合过去一直在工作)。

代码语言:javascript
复制
$ 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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62116172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档