Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3285459
  • 博文数量: 515
  • 博客积分: 5116
  • 博客等级: 大校
  • 技术积分: 4137
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-30 11:24
个人简介

黑马王子就是我! 技术认证:系统分析师,网络规划设计师,网络工程师,信息系统监理师,系统集成项目管理师,初级程序员,MCSE,MCDBA,CCNA 目前主攻虚拟化技术,VPN,系统架构,集群和高可用性等。

文章分类

全部博文(515)

文章存档

2023年(11)

2022年(17)

2021年(19)

2020年(28)

2019年(42)

2018年(53)

2017年(41)

2016年(33)

2015年(43)

2014年(25)

2013年(13)

2011年(6)

2010年(28)

2009年(47)

2008年(55)

2007年(26)

2006年(28)

分类: 系统运维

2019-09-18 14:44:15

前端项目需要进行CI/CD集成,CI服务器是linux的,所以需要在服务器上安装npm环境,记录一下安装过程以及碰到的坑。安装很简单,直接下载官网的linux二进制包,并将bin目录设置在环境变量中就ok了,执行

[root@localhost dist]# npm -version
6.4.1 

说明安装成功了,接下来在执行项目的初始化(基于vue-cli)npm install时,却反复提示权限不足

[root@localhost bocsh-vue-admin]# npm install

> nodent-runtime@3.2.1 install /home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime
> node build.js

fs.js:115
    throw err;
    ^

Error: EACCES: permission denied, open '/home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime/dist/index.js'
    at Object.openSync (fs.js:436:3)
    at Object.writeFileSync (fs.js:1187:35)
    at Object. (/home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime/build.js:5:4)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
npm WARN ajv-errors@1.0.0 requires a peer of ajv@>=5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-standard@12.0.0-alpha.0 requires a peer of eslint@>=5.0.0-alpha.2 but none is installed. You must install peer dependencies yourself.
npm WARN bocsh-vue-admin@2.1.0 No repository field.
npm WARN bocsh-vue-admin@2.1.0 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodent-runtime@3.2.1 install: `node build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nodent-runtime@3.2.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 

这里百思不得其解,谷歌了半天,还是官网的一篇文章解决问题,就是更换npm的默认存储库(至于为什么换了就好了,也不明白,我是root用户啊。。),步骤如下:

  1. Back up your computer.
  2. On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global 
  1. Configure npm to use the new directory path:
 npm config set prefix '~/.npm-global' 
  1. In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH 
  1. On the command line, update your system variables:
 source ~/.profile 
  1. To test your new configuration, install a package globally without using sudo:
npm install -g jshint 

重新安装package顺利下载。
另外还有一个小问题是我们放在版本库里面的代码是没有node_modules模块的,这样的话CI服务器每次检出后都要执行npm install去下载所有的依赖modules,效率比较低,这边的解决方案是先把node_modules目录放在服务器某个位置,在CI脚本中增加

ln -s 源路径  目标路径 

建立软连接,这样每次编译的时候就不需要都执行npm install了。
总结:其实也没啥好总结的,碰到问题多看官网多看英文文档(能谷歌最好),一般都比较靠谱。
官网文章链接

阅读(4373) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~