【问题标题】:How do I Properly run NPM Install in Visual Studio Team Services Build Agent如何在 Visual Studio Team Services 构建代理中正确运行 NPM 安装
【发布时间】:2016-07-05 07:15:39
【问题描述】:

我在为 Visual Studio Team Services(以前的 Visual Studio Online)中的自动构建设置 NPM 任务时遇到问题。有两个问题:

  1. 缓存锁定错误(如下所示)。
  2. 速度非常慢——十几个包裹需要 45 多分钟。

我添加了 --cache 参数,但这似乎没有帮助。

npm install --dev --cache $(Agent.BuildDirectory)\b

二进制文件夹似乎是缓存的正确位置,但老实说,我不确定。这里有一些文档:

https://msdn.microsoft.com/Library/vs/alm/Build/scripts/variables#AgentVariables

感谢任何建议...

当前配置:

构建控制台输出:

Set workingFolder to default: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.97.1\tasks\Npm\0.2.7
##[debug]check path : C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.97.1\tasks\Npm\0.2.7\task.json
##[debug]set resource file to: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.97.1\tasks\Npm\0.2.7\task.json
##[debug]system.culture=en-US
##[debug]check path : C:\Program Files\nodejs\npm.cmd
##[debug]npm=C:\Program Files\nodejs\npm.cmd
##[debug]cwd=C:\a\1\s\com.example.web
##[debug]path exists: C:\a\1\s\com.example.web
##[debug]command=install
##[debug]C:\Program Files\nodejs\npm.cmd arg: install
##[debug]arguments=--dev --cache C:\a\1\b
##[debug]C:\Program Files\nodejs\npm.cmd arg: --dev --cache C:\a\1\b
##[debug]exec tool: C:\Program Files\nodejs\npm.cmd
##[debug]Arguments:
##[debug]   install
##[debug]   --dev
##[debug]   --cache
##[debug]   C:\a\1\b
[command]C:\Program Files\nodejs\npm.cmd install --dev --cache C:\a\1\b
npm WARN deprecated graceful-fs@3.0.8: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
npm WARN deprecated sf-lint@1.0.2: Use eslint-config-simplifield instead.
npm WARN deprecated lodash@2.4.1: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated lodash@0.9.2: Grunt needs your help! See https://github.com/gruntjs/grunt/issues/1403.
npm ERR! addLocal Could not install C:\a\1\s\com.example.web\@shinnn\eslint-config@>=0.0.5 <0.0.6\fixtures
npm WARN deprecated phantomjs@2.1.3: Package renamed to phantomjs-prebuilt. Please update 'phantomjs' package references to 'phantomjs-prebuilt'
npm WARN peerDependencies The peer dependency qunitjs@^1.14.0 included from karma-qunit will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN package.json Dependency 'mocha' exists in both dependencies and devDependencies, using 'mocha@*' from dependencies
npm WARN package.json Dependency 'mocha' exists in both dependencies and devDependencies, using 'mocha@*' from dependencies
npm ERR! addLocal Could not install C:\a\1\s\com.example.web\@shinnn\eslint-config@>=0.0.4 <0.0.5\fixtures
> cson@1.6.2 preinstall C:\a\1\s\com.example.web\node_modules\gulp-uglify\node_modules\uglify-save-license\node_modules\grunt-replace\node_modules\applause\node_modules\cson
> node ./cyclic.js
npm WARN locking Error: EMFILE, open 'C:\a\1\b\_locks\strip-ansi-0bb45da2369f5768.lock.STALE.STALE.STALE'
npm WARN locking     at Error (native)
npm WARN locking  C:\a\1\b\_locks\strip-ansi-0bb45da2369f5768.lock failed { [Error: EMFILE, open 'C:\a\1\b\_locks\strip-ansi-0bb45da2369f5768.lock.STALE.STALE.STALE']
npm WARN locking   errno: -4066,
npm WARN locking   code: 'EMFILE',
npm WARN locking   path: 'C:\\a\\1\\b\\_locks\\strip-ansi-0bb45da2369f5768.lock.STALE.STALE.STALE' }
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--dev" "--cache" "C:\\a\\1\\b"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3
2016-03-30T14:15:17.4509244Z npm ERR! Attempt to unlock C:\a\1\s\com.example.web\node_modules\gulp-imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\compare-size\node_modules\ava\node_modules\chalk\node_modules\strip-ansi, which hasn't been locked
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm WARN locking Error: EMFILE, open 'C:\a\1\b\_locks\ansi-styles-cedcc1e1e4774cd0.lock.STALE.STALE.STALE'
npm WARN locking     at Error (native)
npm WARN locking  C:\a\1\b\_locks\ansi-styles-cedcc1e1e4774cd0.lock failed { [Error: EMFILE, open 'C:\a\1\b\_locks\ansi-styles-cedcc1e1e4774cd0.lock.STALE.STALE.STALE']
npm WARN locking   errno: -4066,
npm WARN locking   code: 'EMFILE',
npm WARN locking   path: 'C:\\a\\1\\b\\_locks\\ansi-styles-cedcc1e1e4774cd0.lock.STALE.STALE.STALE' }
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--dev" "--cache" "C:\\a\\1\\b"
npm ERR! node v0.12.7
npm ERR! npm  v2.11.3
npm ERR! Attempt to unlock C:\a\1\s\com.example.web\node_modules\gulp-imagemin\node_modules\imagemin-pngquant\node_modules\pngquant-bin\node_modules\compare-size\node_modules\ava\node_modules\chalk\node_modules\ansi-styles, which hasn't been locked
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm WARN locking Error: EMFILE, open 'C:\a\1\b\_locks\has-ansi-819c7cca16ab7ac8.lock.STALE.STALE.STALE'
npm WARN locking     at Error (native)
2016-03-30T14:15:17.5709240Z npm WARN locking  C:\a\1\b\_locks\has-ansi-819c7cca16ab7ac8.lock failed { [Error: EMFILE, open 'C:\a\1\b\_locks\has-ansi-819c7cca16ab7ac8.lock.STALE.STALE.STALE']

【问题讨论】:

  • 我似乎找不到关于 --dev 和 --cache 标志的文档,你能给我一些指点吗?
  • 老实说,这些标志不应该是必需的 - 请参阅下面的答案。在全球范围内更新 NPM 就成功了。
  • 我明白了。我实际上是在尝试避免在每次构建时下载所有 node_modules,我认为这个 --cache 标志会有所帮助。我想全局安装 npm 解决了您的锁定文件问题,但没有解决 node_modules 重新下载问题?
  • 还试图不必在每次构建时都安装 node_modules 文件夹,并且不希望它们成为工件的一部分。你知道怎么做吗?
  • @Philip - 不知道,但我发现 MS 构建支持团队非常有帮助。在构建页面中,单击帮助,然后点击支持链接,直到您记录工单。他们反应灵敏。

标签: npm azure-devops


【解决方案1】:

重新安装 NPM 解决了我的问题:

npm install npm -g

具体来说,我将带圆圈的任务添加到我的构建中:

【讨论】:

  • 非常感谢您的回答 :)
  • 您可以禁用此构建任务以节省未来构建的时间,直到再次需要它
  • 只是出于好奇,有没有这个步骤的安装时间有什么区别?
  • 我不记得它在随后的运行中很重要。
猜你喜欢
  • 1970-01-01
  • 2016-10-04
  • 1970-01-01
  • 2013-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-30
  • 2017-11-26
相关资源
最近更新 更多