homestead環境中使用Laravel Mix報錯的解決方法

報錯信息彙總(解決方案在文章下面)

報錯信息1:
此報錯在執行yarn install命令時彈出

error An unexpected error occurred: "EPROTO: protocol error, symlink '../../../parser/bin/babel-parser.js' -> '/home/vagrant/Code/cloudsystem/node_modules/@babel/core/node_modules/.bin/parser'".
info If you think this is a bug, please open a bug report with the information provided in "/home/vagrant/Code/cloudsystem/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

報錯信息2:
此報錯在執行npm run watch-poll命令時彈出

sh: 1: cross-env: not found
npm ERR! file shnpm ERR! code ELIFECYCLE
npm ERR! errno ENOENTnpm ERR! syscall spawn
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js "--watch" "--watch-poll"`
npm ERR! spawn ENOENT
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! A complete log of this run can be found in:npm ERR!     /home/vagrant/.npm/_logs/2019-06-10T01_49_28_082Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ watch: `npm run development -- --watch "--watch-poll"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ watch script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2019-06-10T01_49_28_139Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ watch-poll: `npm run watch -- --watch-poll`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ watch-poll script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vagrant/.npm/_logs/2019-06-10T01_49_28_187Z-debug.log

解決方案

問題1的解決方案:
為命令添加–no-bin-links參數

yarn install --no-bin-links

問題2的解決方案:
步驟一:
修改項目根目錄下的package.json,將`scripts中的內容修改為以下(刪掉原內容粘貼新內容即可):

"dev": "npm run development",
"development": "NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"

如圖:
修改後的package.json文件

步驟二:
執行命令

npm run watch --watch-poll

此時Laravel Mix即可成功運行。

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha Code