[英]angular2: Cannot find module '@angular/core'
I followed the angular2 quick start to create my project and everything works fine but my "tsc -w" command line keeps on telling me: 我按照angular2 快速启动创建我的项目,一切正常,但我的“tsc -w”命令行不断告诉我:
app/components/company/company.ts(1,36): error TS2307: Cannot find module '@angular/core'.
app/components/company/company.ts(5,22): error TS2307: Cannot find module '@angular/router'.
app/components/mission/mission.ts(1,36): error TS2307: Cannot find module '@angular/core'.
app/components/mission/mission.ts(3,22): error TS2307: Cannot find module '@angular/router'.
And there is plenty of other line like this. 还有很多其他的这样的路线。 However, everything is compiled successfully and my application works fine, but it's quite annoying to have all these warnings/errors as real errors something get lost in the middle of them. 但是,一切都已成功编译,我的应用程序工作正常,但将所有这些警告/错误作为真正的错误在它们中间丢失是非常烦人的。
I'm using Angular2 rc1, TypeScript 1.8.10, WebStorm EAP (altough I'm not using the WebStorm TypeScript compilation system, I'm relying on an open terminal with "tsc -w" command line). 我正在使用Angular2 rc1,TypeScript 1.8.10,WebStorm EAP(尽管我没有使用WebStorm TypeScript编译系统,我依赖于带有“tsc -w”命令行的开放式终端)。
I checked other question related to that on SO, but I didn't find anything that really helped me. 我在SO上检查了与之相关的其他问题,但我找不到任何真正帮助我的东西。
Update 更新
Here is my tsconfig.json file: 这是我的tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "system",
"noImplicitAny": false,
"outDir": "js",
"rootDir": "app"
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
You should use the moduleResolution
attribute to node
: 您应该将moduleResolution
属性用于node
:
{
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "system",
"moduleResolution": "node", // <-----
"noImplicitAny": false,
"outDir": "js",
"rootDir": "app"
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
You first need to add typings at global level as below. 您首先需要在全局级别添加类型,如下所示。
npm install -g typings
Then create typings.json using below command. 然后使用下面的命令创建typings.json。
typings init
Paste below code in typings.json 粘贴在typings.json中的代码下面
{
"name": "ng2-application",
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160909174046"
}
}
Now you need to add below code in tsconfig.json 现在您需要在tsconfig.json中添加以下代码
"compilerOptions": {
"moduleResolution": "node"
}
After doing above steps you will able to get definitions on F12. 完成上述步骤后,您将能够获得F12的定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.