我已经将npm脚本设置为几个同步命令。开始命令是npm run clean:install"。
以下是顺序:
"install:all": "npm install && bower install", "clean": "npm run rimraf -- node_modules doc typings coverage wwwroot bower_components" "preclean:install": "npm run clean", "clean:install": "npm set progress=false && npm run install:all"
如果所有目录都存在,则工作正常。问题是,如果已经删除了任何目录,则脚本与代码1一起存在,并阻止所有其他同步脚本运行。
因此,这意味着它无法运行最初的命令clean:install,即“"clean:install": "npm set progress=false && npm run install:all”。
国家预防机制的错误:
npm ERR! angular2-webpack-starter@5.0.4 clean: `npm cache clean && npm run
rimraf -- node_modules doc typings coverage wwwroot bower_components`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-webpack-starter@5.0.4 clean script 'npm cache clean && npm run rimraf -- node_modules doc typings coverage wwwroot bower_components'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-webpack-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm cache clean && npm run rimraf -- node_modules doc typings coverage wwwroot bower_components
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-webpack-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-webpack-starter
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?最后一行给出了答案。它想要node_modules,但找不到它,所以它失败了。
如何使我的脚本继续执行以忽略这些失败(缺少目录)?
node_modules编辑:发生此错误是因为rimraf正在删除、、和擦除自身。一旦清除了该文件夹,rimraf就会消失并退出代码1。我是否可以排除node_modules中的rimraf文件夹,以便它正确存在?
发布于 2016-05-08 00:38:19
解决办法有点棘手。问题在于,由于rimraf只在本地node_modules中安装,所以它正在自行删除。因此,一旦它删除了node_modules dir,程序就死了。
我意识到有必要添加一个任务,让它在全球范围内安装rimraf。执行的第一个任务是install:all。那么rimraf就走上了全球之路。然而,rimraf是许多其他node_modules、的依赖项,因此它一直在本地安装,因此忽略了全局路径。仍然在引用本地node_modules文件夹,因此一直处于死亡状态。
的诀窍是在执行任何rimraf命令之前在本地卸载rimraf。现在它被迫使用全局路径,因为它不存在于本地。
"preinstall:all": "npm install typings webpack-dev-server rimraf webpack -g",
"install:all": "npm install && bower install",
"prerimraf": "npm uninstall rimraf",
"rimraf": "rimraf",
"clean": "npm run rimraf -- node_modules doc typings coverage wwwroot bower_components"
"preclean:install": "npm run clean",
"clean:install": "npm set progress=false && npm run install:all"在项目加载上执行install:all之后(在Visual 2015中,任务运行器有一个名为Project Open的绑定),有时我想清理所有的东西并重新开始。现在,我可以简单地执行clean:install并卸载node_modules并立即重新安装,没有问题!退出代码0。甜!
发布于 2016-05-08 00:34:44
我(可能)在看你正在使用的这个样板工程。你看过说明书了吗?他们要求您在使用该项目之前运行npm install typings webpack-dev-server rimraf webpack -g,其中包括安装 globally。如果您没有这样做,使用npm run clean:install或调用此脚本的任何东西都会失败,因为在本地node_modules中找不到rimraf模块(如果已经删除了),或者它将自己删除。
https://stackoverflow.com/questions/37094878
复制相似问题