繁体   English   中英

angular2:找不到模块'@ angular / core'

[英]angular2: Cannot find module '@angular/core'

我按照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'.

还有很多其他的这样的路线。 但是,一切都已成功编译,我的应用程序工作正常,但将所有这些警告/错误作为真正的错误在它们中间丢失是非常烦人的。

我正在使用Angular2 rc1,TypeScript 1.8.10,WebStorm EAP(尽管我没有使用WebStorm TypeScript编译系统,我依赖于带有“tsc -w”命令行的开放式终端)。

我在SO上检查了与之相关的其他问题,但我找不到任何真正帮助我的东西。

更新

这是我的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"
  ]
}

您应该将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"
  ]
}

您首先需要在全局级别添加类型,如下所示。

npm install -g typings

然后使用下面的命令创建typings.json。

typings init

粘贴在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"
  }
}

现在您需要在tsconfig.json中添加以下代码

 "compilerOptions": {
        "moduleResolution": "node"
       }

完成上述步骤后,您将能够获得F12的定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM