laravel使用npm構建報錯laravel-mix/src/Mix.js:18 static _primary = null

問題

今天在使用npm構建laravel8項目時出現報錯: laravel使用npm構建報錯laravel-mix/src/Mix.js:18 static _primary = null

> mix watch -- --watch-options-poll=1000

[webpack-cli] /www/wwwroot/xxx/node_modules/laravel-mix/src/Mix.js:18
    static _primary = null;
                    ^

SyntaxError: Unexpected token =
    at new Script (vm.js:83:7)
    at NativeCompileCache._moduleCompile (/www/wwwroot/xxx/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/www/wwwroot/xxx/node_modules/v8-compile-cache/v8-compile-cache.js:184:36)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (/www/wwwroot/xxx/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at module.exports (/www/wwwroot/xxx/node_modules/laravel-mix/setup/webpack.config.js:2:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ watch-poll: `mix watch -- --watch-options-poll=1000`
npm ERR! Exit status 2
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!     /root/.npm/_logs/2021-01-21T09_04_30_514Z-debug.log

方法

於是上網查了很多資料,很多都是說,刪除node_modules重裝,或者更換taobao鏡像,但是試了都不好使, 最後自己摸索,發現是node版本問題,於是,解決這裏的問題只需要升級node版本即可

使用命令:(後兩條命令選擇一條即可)

# 安裝n依賴包
npm install -g n
# 安裝最新穩定版(推薦)
n stable
# 安裝最新版
n latest

原文鏈接:https://www.wjcms.net/archives/laravel%E4%BD%BF%E7%94%A8npm%E6%9E%84%E5%BB%BA%E6%8A%A5%E9%94%99laravel-mixsrcmixjs18staticprimarynull

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章