Webpack & Webpack-cli 安裝成功後檢視 webpack -v報錯

2020-11-08 11:01:17

問題

1. 安裝webpack webpack-cli

npm install -g webpack webpack-cli
在這裡插入圖片描述

2. 檢視webpack 版本

webpack -v

報錯

/usr/local/lib/node_modules/webpack/lib/cli.js:66
                        .replace(
                        ^

SyntaxError: Invalid regular expression: /(\p{Uppercase_Letter}+|\p{Lowercase_Letter}|\d)(\p{Uppercase_Letter}+)/: Invalid escape
    at pathToArgumentName (/usr/local/lib/node_modules/webpack/lib/cli.js:66:4)
    at addFlag (/usr/local/lib/node_modules/webpack/lib/cli.js:170:16)
    at traverse (/usr/local/lib/node_modules/webpack/lib/cli.js:243:21)
    at traverse (/usr/local/lib/node_modules/webpack/lib/cli.js:299:23)
    at traverse (/usr/local/lib/node_modules/webpack/lib/cli.js:248:24)
    at Object.getArguments (/usr/local/lib/node_modules/webpack/lib/cli.js:308:2)
    at Object.<anonymous> (/usr/local/lib/node_modules/webpack-cli/lib/utils/cli-flags.js:245:30)
    at Module._compile (/usr/local/lib/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)

解決

1. 檢視node版本

node -v
v9.11.2

發現node版本 不是最新的,官網下載安裝最新版本的Node(LTS)

node -v
v14.15.0

2. 升級npm

npm i -g npm

3. 檢視webpack版本

webpack -v

webpack-cli 4.2.0

webpack 5.4.0

(成功啦~ 撒花🎉撒花🎉 吼吼~)