【问题标题】:cannot find module "angular2/angular"找不到模块“angular2/angular”
【发布时间】:2015-12-05 16:28:17
【问题描述】:

我正在关注 https://angular.io/guide/quickstart 的 Angular js 教程

我正在尝试使用此代码:

import {bootstrap, Component} from 'angular2/angular2';
@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);

但我收到此错误:

找不到模块“angular2/angular”

这是我的文件夹结构:

【问题讨论】:

标签: angular typescript


【解决方案1】:

tsd for angular2 实际上并没有在您的类型目录中创建类型文件,而是需要使用节点安装:

npm install -save angular2

然后在你的tsdconfig.json中,需要在compilerOptions下开启node模块解析:

"moduleResolution": "node"

【讨论】:

  • 感谢您的快速回复。我将 tsconfig.json 放置到 root 但得到不同的错误prntscr.com/9anlzk。我的 tsconfig 文件如下所示:prntscr.com/9anmn1
  • 我认为它也不应该在 wwwroot 下,就在与 project.json 相同级别的项目根目录下。这是我的项目结构imgur.com/gV1QLLv
  • 那也没用。我开始找不到模块“angular2/angular”请检查这个prntscr.com/9anwyq。顺便说一句,我没有使用 gulpfile。
  • 你能把typings文件夹也移动到根目录吗?这个想法是您的脚本/tsd/中间文件进入项目的根目录,构建转换为 js,而 js 进入您部署的 wwwroot。
  • 这没有帮助。请查看dropbox.com/s/dgdibivnl4c55vf/Angular2Typescript.rar?dl=0。顺便说一句,我使用的是 beta 8。请查看prntscr.com/9ax6gx
猜你喜欢
  • 2016-09-25
  • 1970-01-01
  • 1970-01-01
  • 2016-04-14
  • 2016-10-09
  • 1970-01-01
  • 1970-01-01
  • 2016-05-03
  • 1970-01-01
相关资源
最近更新 更多