jenkins执行npm install失败:Error: yorkie@2.0.0 install: `node bin/install.js

最近新做一个使用vue开发的后台管理系统,统一交由服务端和后台逻辑一起进行更新操作,前端只负责开发,构建工具使用的jenkins,服务端需要在jenkins上面打包,并通过映射到dist文件夹下的index.html来实现访问打包后的项目
在jenkins时运行npm install命令时报错误如下:

yorkie@2.0.0 install /data/.jenkins/workspace/local5-sc-console/sc-admin-view/node_modules/yorkie
node bin/install.js

internal/modules/cjs/loader.js:983
throw err;
^

Error: Cannot find module ‘/data/.jenkins/workspace/local5-sc-console/sc-admin-view/node_modules/yorkie/bin/install.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack: []
}
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yorkie@2.0.0 install: node bin/install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yorkie@2.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

解决办法:后尝试使用淘宝镜像和cnpm命令都失败,最后使用sudo npm install成功下载了依赖

### Jenkins 使用指定镜像源 `npm install` 打包不全解决方案 #### 配置全局 NPM 源 为了确保所有依赖项都能正确下载,可以在构建脚本之前配置NPM使用国内镜像源。通过设置环境变量或直接在Jenkinsfile中加入如下命令来实现: ```groovy sh 'npm config set registry https://registry.npmmirror.com' ``` 这一步骤能够保证后续所有的`npm install`操作都会从指定的镜像源获取资源[^2]。 #### 清理缓存并重新安装依赖 有时本地缓存可能会导致某些文件未能成功更新或下载完全,在执行安装命令前先清理现有缓存有助于解决问题: ```bash rm -rf node_modules/ npm cache clean --force npm install --no-package-lock --prefer-offline --production=false --registry=https://registry.npmmirror.com ``` 上述命令不仅指定了注册表URL还包含了其他参数以优化安装过程,比如忽略锁文件(`--no-package-lock`)防止版本冲突;优先离线模式(`--prefer-offline`)加快速度;以及包含开发依赖(`--production=false`)[^1]。 #### 修改 package.json 中的 registry 字段 (可选) 对于一些特殊情况下的项目结构,可能需要更进一步调整`package.json`中的默认注册表地址。可以通过编辑该文件内的`publishConfig.registry`字段指向新源: ```json { "name": "...", ... "publishConfig": { "registry":"https://registry.npmmirror.com" } } ``` 此改动仅影响发布行为而非安装流程,但在特定场景下也可能间接帮助解决部分问题[^4]。 #### 设置合适的权限 当遇到由于权限不足引起的错误时,可以尝试提升PowerShell或其他shell工具的执行策略级别以便顺利完成必要的配置变更: ```powershell Set-ExecutionPolicy RemoteSigned -Scope Process ``` 这条指令允许当前进程内运行未经签名的脚本,从而绕过潜在的安全限制[^3]。 #### 定期验证和同步依赖关系 最后定期检查项目的依赖状态,并保持与官方仓库的一致性非常重要。利用`npm outdated`命令可以帮助识别哪些模块存在可用的新版本,进而决定是否要升级它们。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值