【发布时间】:2022-01-11 01:34:04
【问题描述】:
我正在创建实际上包含 3 个不同项目的构建。其中 2 个我需要进行 npm install ,第三个我需要在打包和创建构建之前进行 bower install 。所以我在这里寻找优化机会并创建了这个脚本:
install_dependency.sh
# $1 = project_1 $2=project_2 $3=project_3
npm install --global bower ng-cli && <!-- This runs 1st -->
echo "Global Installation complete" && <!-- This runs 2nd -->
node --version && npm --version && <!-- This runs 3rd -->
parallel --halt 2 ::: \ <!-- From here till END runs in parallel -->
"cd $1; npm install" \
"cd $1; npm install --only=dev" \
"cd $2; npm install" \
"cd $2; npm install --only=dev" \ <!-- "END" Till here it runs parallel-->
"cd $3; bower --allow-root install" && echo All is OK && <!-- It runs next -->
cd $1; npm run build_stage && echo build created && <!-- It runs next -->
cd $2; npm run build && echo build created <!-- It runs next -->
但我似乎无法并行运行 npm install ,因为它会导致一些冲突并失败并出现如下随机错误:
> node-sass@4.9.4 install /data/project/uiv2/node_modules/node-sass
> node scripts/install.js
npm WARN deprecated typings@1.5.0: Typings is deprecated in favor of NPM @types -- see README for more information
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated gulp-util@3.0.7: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated hoek@2.16.3: The major version is no longer supported. Please update to 4.x or newer
module.js:550
throw err;
^
Error: Cannot find module 'inherits'
at Function.Module._resolveFilename (module.js:548:15)
如果可能,请帮我解决这个问题。如果不是,那么解决这个问题的最佳方法是什么。
【问题讨论】:
-
这些项目是否相互依赖,例如
npm link?如果是,那么可能并行安装不是这里的选项。 -
不,它们是独立的。他们有不同的 package.json 文件,他们只是共享相同的节点版本
-
docs.npmjs.com/cli/cache 应该会有所帮助。默认值:
~/.npm在 Posix 上,或%AppData%/npm-cache在 Windows 上。那么如果你同时运行它们,它们可以尝试修改相同的缓存,导致随机错误?如果你一一做,它们安装正确吗? -
是的,按顺序运行效果很好
-
快速搜索指向一些相关的问题:-github.com/npm/npm/issues/5948-github.com/npm/npm/issues/2500我不知道他们是否有解决方案,但直觉上我会查看
docker,在其中运行构建码头集装箱。
标签: node.js shell npm npm-install