Listening to the Words

homestead环境下安装npm各种报错

安装laravel前端工作流时,使用npm或者yarn执行如下命令:

$ yarn install –no-bin-links
$ yarn add cross-env
$ npm run dev
$ npm run watch-poll

然后结果各种报错,试了各种办法仍然解决不了问题.
最后在OverStackFlow论坛找到解决办法:

更新nodejs到最新的版本

sudo apt-get install --yes nodejs
curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash -

国内网络环境不好,需要很长时间.具体视网络环境而定

安装npm最新版本

sudo npm -g install npm@latest

执行安装

在laravel项目文件下强制执行安装

sudo npm install --no-bin-links
sudo npm cache clear
sudo npm install --force --no-bin-links

出现 gulp错误时.重新安装node-sass

sudo npm rebuild node-sass --no-bin-links

–no-bin-links命令一定要带着,不然报错误

安装过程出出现错误执行以下代码

sudo npm cache clear

再次执行npm run dev

到这部基本就能安装成功了,如果出现:

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ development: `NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules
/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

再次执行

$ npm rebuild node-sass –no-bin-links

原文地址 https://stackoverflow.com/questions/33186123/npm-install-errors-on-vagrant-homestead-windows-eproto-protocol-error-symlink

点赞