npm start不能运行,npm(ERR!在apm@0.0.0启动脚本中失败。)

3
我正在使用链接中的示例学习angular。但是,当我运行npm start时,它显示错误。我搜索了解决方案,要求更新npm或angular版本,但我已经使用最新版本如下: npm -v = 6.4.1 node -v = 10.9.0 angular CLI = 6.1.5 我正在使用Windows 7。
 > apm@0.0.0 start F:\Angular\Angular-GettingStarted-master\APM-Start
 > ng serve -o

 npm ERR! file bash
 npm ERR! path bash
 npm ERR! code ELIFECYCLE
 npm ERR! errno ENOENT
 npm ERR! syscall spawn bash
 npm ERR! apm@0.0.0 start: `ng serve -o`
 npm ERR! spawn bash ENOENT
 npm ERR!
 npm ERR! Failed at the apm@0.0.0 start script.
 npm ERR! This is probably not a problem with npm. There is likely 
 additional logging output above.

 npm ERR! A complete log of this run can be found in:
 npm ERR!     C:\Users\AppData\Roaming\npm-cache\_logs\2018-09- 
 05T16_12_41_076Z-debug.log

你再用哪个链接?它没有作为这个问题的一部分加载。请考虑再次添加它。 - SiddAjmera
我更新了问题中的链接。 - hrishi
2
在尝试 ng serve 之前,你是否运行了 npm install 命令? - peinearydevelopment
1
此外,如果未全局安装angular-cli,在执行npm install之后,您需要按以下方式运行命令:node_modules/.bin/ng servenpm run start - peinearydevelopment
你应该运行 ng serve 而不是 npm start - SiddAjmera
显示剩余4条评论
2个回答

8

您的 Node 版本似乎过高,请将 Node 版本降级至 8.9.0。请注意,基于 Node 的 npm 版本也需要降级。

删除 node_modules 文件夹。

按以下顺序运行命令:

npm cache clean --force

npm install

npm rebuild node-sass

然后尝试运行:ng serve


我安装了版本8.9.0和npm,但npm -v会出现错误信息:“Error: Cannot find module 'C:\Windows\System32\node_modules\npm\bin\npm-cli.js'”。我设置了环境变量为“C:\Program Files\nodejs”,但仍然出现相同的错误。 - hrishi
System32 中没有 node_modules。 - hrishi
你以管理员身份安装了Node吗?如果没有,请尝试以管理员身份安装。 - Gourav Pokharkar
是的,我以管理员身份安装了它。 - hrishi
干得好。为你感到高兴。 - Gourav Pokharkar
显示剩余2条评论

1

哇,太疯狂了。我通过以下方式解决了这个问题:

  1. 卸载了 Node 并重新启动了我的机器。
  2. 此处 下载了一个新版本的 Node,它是 LTS 版本。
  3. 安装了我下载的这个新版本的 Node。
  4. 在项目目录中运行了 npm cache clean --force
  5. 在项目目录中运行了 npm install
  6. 然后,它活过来了!!!它工作了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接