【问题标题】:changing angular2/core directory not working更改 angular2/core 目录不起作用
【发布时间】:2016-04-12 20:20:42
【问题描述】:

当我使用时:

import {Component} from 'angular2/core';

app.component.ts 我的应用程序将成功运行,但编译器抛出 Error:(1, 25) TS2307: Cannot find module 'angular2/core'而核心文件位于 node_modules/angular2/core 目录中!

当我更改核心目录时,我的应用程序无法运行,但编译器正常! 我正在处理ANGULAR: 5 MIN QUICKSTART

Project Folders Structure

我的 tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

【问题讨论】:

  • 能否提供tsconfig.json文件的内容?谢谢!

标签: typescript angular


【解决方案1】:

您遇到了错误,因为 TypeScript 编译器找不到 core.d.ts 文件。您需要具有以下配置才能使其工作。注意moduleResolution属性必须设置为node

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node", // <----------
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

【讨论】:

  • 我的配置文件是这样的,但是还是不行。
  • 你需要在index.htmlSystem.config()主函数中使用system.jsmap属性
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-10
  • 2019-01-23
  • 2016-03-14
  • 1970-01-01
  • 2013-10-12
  • 1970-01-01
  • 2022-10-06
相关资源
最近更新 更多