用角度标记的IntelliJ的IntelliJ TypeScript导入

时间:2017-10-17 13:29:00

标签: angular intellij-idea

我正在使用IntelliJ IDEA 2017.2.4来开发Angular(4而不是js)应用。一切正常并且运行良好,但IntelliJ标记了带有红色波形的TypeScript文件中的所有@angular导入。

错误讯息为TS2307: Cannot find module '@nagular/abc'

Jetbrain的支持Typescript does not resolve modules through tsconfig.json's baseUrl

也有问题

enter image description here

这是我的tsconfig.json文件。

请注意,tsconfig.json文件不存储在项目的根目录中,而是存储在./app/ui目录中 - 如果这很重要。

{
  "compilerOptions": {
   "alwaysStrict": true,
   "noImplicitReturns": true,
   "emitDecoratorMetadata": true,
   "experimentalDecorators": true,
   "module": "system",
   "target": "es5",
   "removeComments": true,
   "suppressImplicitAnyIndexErrors": true,
   "outDir": "generated",
   "inlineSourceMap": true,
   "importHelpers": true,
   "baseUrl": ".",
   "paths": {
     "tslib": [
      "../../node_modules/tslib/tslib.d.ts"
     ]
   },
   "skipLibCheck": true,
   "downlevelIteration": true
  },
  "exclude": [
   "lib"
  ]
}

2 个答案:

答案 0 :(得分:1)

你所有的角度相关包都应该在。 例如:

node_modules/@angular/common/index.d.ts
node_modules/@angular/compiler/index.d.ts
node_modules/@angular/core/index.d.ts
node_modules/@angular/http/index.d.ts
node_modules/@angular/platform-browser/index.d.ts
node_modules/@angular/platform-browser-dynamic/index.d.ts
node_modules/@angular/router/index.d.ts
node_modules/@angular/router-deprecated/index.d.ts

但是,如果您使用标准快速入门https://angular.io/docs/ts/latest/quickstart.html中的package.json文件并运行npm install

,则所有这些都应该存在

同时检查IDE的tsconfig.json设置

File->settings->Languages & Frameworks -> TypeScript ->enable typescript compiler & Use tsconfig.json

答案 1 :(得分:0)

使用"module": "system" TypeScript使用不解析节点模块的经典模块解析时,请参阅https://www.typescriptlang.org/docs/handbook/module-resolution.html

上的详细信息

要使其工作,您需要切换到不同的模块系统,如CommonJS,或者可能有另一个配置在使用"module": "system"时明确地在解析中包含node_modules。