首页 > 解决方案 > 由于文件锁定,jenkins 上的 npm 安装失败

问题描述

npm install我有一个在某个时候运行的 powershell 构建脚本。我在网上搜索了这个问题,但找不到任何有用的东西。我看到有人建议在Windows Defenderjenkins 文件夹中放置一个例外,因为它正在锁定文件。我做到了,仍然没有运气。

我不认为脚本对我有任何锁定,我只是在运行 npm install。奇怪的是,这并不总是发生,有时有效,有时无效。

26610 verbose stack Error: EPERM: operation not permitted, unlink 'C:\Jenkins\workspace\...\node_modules\.staging\highcharts-705cfa89\highcharts.src.js'
26612 verbose Windows_NT 10.0.18363
26613 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
26614 verbose node v12.18.2
26615 verbose npm  v6.14.5
26616 error code EPERM
26617 error syscall unlink
26618 error path C:\Jenkins\workspace\...\node_modules\.staging\highcharts-705cfa89\highcharts.src.js
26619 error errno -4048
26620 error Error: EPERM: operation not permitted, unlink 'C:\Jenkins\workspace\...\node_modules\.staging\highcharts-705cfa89\highcharts.src.js'
26620 error  [OperationalError: EPERM: operation not permitted, unlink 'C:\Jenkins\workspace\...\node_modules\.staging\highcharts-705cfa89\highcharts.src.js'] {
26620 error   cause: [Error: EPERM: operation not permitted, unlink 'C:\Jenkins\workspace\...\node_modules\.staging\highcharts-705cfa89\highcharts.src.js'] {
26620 error     errno: -4048,
26620 error     code: 'EPERM',
26620 error     syscall: 'unlink',
26620 error     path: 'C:\\Jenkins\\workspace\\...\\node_modules\\.staging\\highcharts-705cfa89\\highcharts.src.js'
26620 error   },
26620 error   errno: -4048,
26620 error   code: 'EPERM',
26620 error   syscall: 'unlink',
26620 error   path: 'C:\\Jenkins\\workspace\\...\\node_modules\\.staging\\highcharts-705cfa89\\highcharts.src.js',
26620 error   parent: 'react'
26620 error }
26621 error The operation was rejected by your operating system.
26621 error It's possible that the file was already in use (by a text editor or antivirus),
26621 error or that you lack permissions to access it.
26621 error
26621 error If you believe this might be a permissions issue, please double-check the
26621 error permissions of the file and its containing directories, or try running
26621 error the command again as root/Administrator.
26622 verbose exit [ -4048, true ]

标签: node.jsjenkinsnpm

解决方案


对于遇到此问题的任何人

package-lock.json就是问题所在。我们有一个我们使用的 npm 包的 proget 提要,但是package-lock.json将注册表设置为默认的 npm 注册表。这就是导致问题的原因。

解决方案是删除文件或在使用正确的注册表package-lock.json运行后提交它。npm install


推荐阅读