【问题标题】:npm start Error 2npm 启动错误 2
【发布时间】:2016-05-25 15:11:10
【问题描述】:

在运行“npm start”时,我收到以下错误:

app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'.
    app/main.ts(1,30): error TS2307: Cannot find module '@angular/platform-browser-dynamic'.

npm ERR! weird error 2

npm WARN This failure might be due to the use of legacy binary "node"

npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

错误发生在运行 typescript 文件时,而不是在 javascript 文件期间。我什至尝试过以下两个命令:

sudo apt-get install nodejs-legacy


sudo npm update -g && sudo npm install -g concurrently lite-server typescript

但错误仍然存​​在。该怎么办? 我正在使用 Ubuntu 14.04 操作系统。节点版本:6.2.0,nodejs:0.10.25 并在 Angular2 上工作。

【问题讨论】:

  • 您能提供您的package.jsontsconfig.json 文件的内容吗?谢谢!
  • 您是否在项目目录中执行了npm install(不是-g 或其他任何操作)?
  • @CherryDT 是的。它没有用。然后我尝试了sudo npm install,它对我有用。但为什么它仍然有效,我不知道。
  • 那么请添加您的解决方案作为答案!

标签: npm angular


【解决方案1】:

而不是使用:npm install。 使用:sudo npm install 在同一目录中,这对我有用。

您也可以:sudo npm install -g 全局安装。 但是,是的,请记住在您的系统中安装最新的 nodejs。 希望对您有所帮助。

别忘了使用 angular2 库。

要消除以下错误: app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'. app/main.ts(1,30): error TS2307: Cannot find module '@angular/platform-browser-dynamic'.

做: npm install angular2 --save

并将导入替换为:

import {Component} from 'angular2/core'; import {bootstrap} from 'angular2/platform/browser'; 希望对您有所帮助。如果不确定,请发表评论。

【讨论】:

  • Angular2 包声明已从 RC1 中的 'angular2' 更改为 '@angular'
猜你喜欢
  • 2016-11-10
  • 2020-09-25
  • 2018-09-16
  • 1970-01-01
  • 2014-11-29
  • 2017-12-09
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多