【发布时间】:2019-04-18 11:03:32
【问题描述】:
我从事 Angular 6 项目已经有很长时间了,当我的项目文件夹中有 node_modules 文件夹时,它工作得很好。
我希望能够在我的项目中没有node_modules 的情况下运行我的项目,因此我将node_modules 文件夹移动到父文件夹并在angular.json 中更改了以../node_modules 开头的路径。
我认为它会起作用,但是在我写 npm start 之后我得到了这个错误:
pm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! lg-academy@0.0.0 start: `ng serve --configuration=production --host 0.0.0.0 --port 4200 --verbose --disable-host-check`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the lg-academy@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ofir/.npm/_logs/2018-11-15T1
提前感谢所有帮助者
【问题讨论】:
-
你之前跑过
npm i吗? -
你不能简单地移动
node_modules,它必须在package.json所在的位置——你为什么觉得有必要移动它? -
通常您不会重新定位 node_modules 文件夹。它很重,是的,但是如果您想将项目部署到生产服务器,您只需不上传 node_modules 文件夹即可。您只需要那里的 package.json 文件并在生产服务器上执行“npm install”即可。
-
我不敢这么说,但它应该是那样的。带有 package.json 的项目必须依赖 node_modules 文件夹,该文件夹存储所有项目依赖项。你应该考虑在部署时运行一些脚本来自动
npm install。 -
Angular 应用的生产模式一般是由 build 命令创建的静态文件,所以你在生产中不需要任何这些。
标签: angular npm dependencies node-modules package.json