我正在使用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
也有问题
这是我的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"
]
}
答案 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。