安装 npm 出错的问题

1、先在系统上安装好nodejs和npm

 

sudo apt-get install nodejs-legacy

这一部出错请参考:这里

 

sudo apt-get install npm

2、升级npm为最新版本

 

sudo npm install npm@latest -g

3、安装用于安装nodejs的模块n

 

sudo npm install -g n

4、通过n模块安装指定的nodejs

 

sudo n latest
sudo n stable
sudo n lts

5、查看版本

 

sudo node -v
sudo npm -v

报错:

sudo npm install -g n 
/usr/local/lib/node_modules/npm/bin/npm-cli.js:79
      let notifier = require('update-notifier')({pkg})
      ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) 
not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

原因是第二步的问题

则只需要删除安装的npm

cd /usr/local/lib/node_modules
mv npm/ /tmp/usr_local_lib_node_modules_npm

然后重新执行

sudo npm install -g n 
sudo n stable

就好了,结果如下

sudo n stable

     install : node-v10.6.0
       mkdir : /usr/local/n/versions/node/10.6.0
       fetch : https://nodejs.org/dist/v10.6.0/node-v10.6.0-linux-x64.tar.gz
######################################################################## 100.0%
   installed : v10.6.0

转:https://segmentfault.com/a/1190000007542620

 

webpack出错

sh: 1: webpack: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! superset@0.26.3 build: `NODE_ENV=production webpack --colors --progress`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the superset@0.26.3 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/andy/.npm/_logs/2018-08-28T09_43_09_707Z-debug.log

缺少webpack包

pip install webpack

然后(会出现两个错误,但是不影响)

sudo ./js_build.sh 

执行命令

npm run build

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值