在 Windows 10,执行 npm run dev 时,报错:You are using an unsupported version of Node. Please update to at least Node v12.14

1、在 Laravel 8.6.3 中,Laravel Breeze 安装,执行 npm run dev 时,报错:You are using an unsupported version of Node. Please update to at least Node v12.14。如图1

图1

PS E:\wwwroot\laravel-8-5> php artisan breeze:install
Breeze scaffolding installed successfully.
Please execute the "npm install && npm run dev" command to build your assets.
PS E:\wwwroot\laravel-8-5> npm install
npm WARN notice [SECURITY] lodash has the following vulnerability: 1 high. Go here for more details: https://www.npmjs.com/advisories?search=lodash&version=4.17.21 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN postcss-load-config@3.1.0 requires a peer of ts-node@>=9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-notifier@1.14.1 requires a peer of @types/webpack@^4.41.31 but none is installed. You must install peer dependencies yourself.
npm WARN ws@8.2.3 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@8.2.3 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.

added 812 packages in 126.222s
PS E:\wwwroot\laravel-8-5> npm run dev

> @ dev E:\wwwroot\laravel-8-5
> npm run development


> @ development E:\wwwroot\laravel-8-5
> mix

Error: You are using an unsupported version of Node. Please update to at least Node v12.14
    at assertSupportedNodeVersion (E:\wwwroot\laravel-8-5\node_modules\laravel-mix\src\Engine.js:6:15)
    at executeScript (E:\wwwroot\laravel-8-5\node_modules\laravel-mix\bin\cli.js:61:5)
    at Command.program.command.description.option.action (E:\wwwroot\laravel-8-5\node_modules\laravel-mix\bin\cli.js:47:13)
    at Command.listener [as _actionHandler] (E:\wwwroot\laravel-8-5\node_modules\commander\index.js:922:31)
    at Command._parseCommand (E:\wwwroot\laravel-8-5\node_modules\commander\index.js:1503:14)
    at Command._dispatchSubcommand (E:\wwwroot\laravel-8-5\node_modules\commander\index.js:1443:18)
    at Command._parseCommand (E:\wwwroot\laravel-8-5\node_modules\commander\index.js:1469:12)
    at Command.parse (E:\wwwroot\laravel-8-5\node_modules\commander\index.js:1292:10)
    at Command.parseAsync (E:\wwwroot\laravel-8-5\node_modules\commander\index.js:1318:10)
    at run (E:\wwwroot\laravel-8-5\node_modules\laravel-mix\bin\cli.js:50:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `mix`
npm ERR! Exit status 1
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!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2021-10-21T02_45_05_986Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
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 ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2021-10-21T02_45_06_047Z-debug.log
PS E:\wwwroot\laravel-8-5>

2、查看 Node.js 的版本:v8.10.0。要求的版本至少为:Node v12.14。如图2

图2

PS E:\wwwroot\laravel-8-5> node -v
v8.10.0

3、参考网址:https://www.jianshu.com/p/0f3fdf6c0d5f ,重新安装最新稳定版本。下载 14.18.1 LTS。安装路径与旧版本保持一致:C:/Program Files/nodejs。如图3

图3

4、再次查看 Node.js 的版本:v14.18.1。如图4

图4

PS E:\wwwroot\laravel-8-5> node -v
v8.10.0
PS E:\wwwroot\laravel-8-5> npm -v
5.5.1
PS E:\wwwroot\laravel-8-5> where node
PS E:\wwwroot\laravel-8-5> node -v
v14.18.1
PS E:\wwwroot\laravel-8-5> npm -v
5.5.1

5、npm WARN npm npm does not support Node.js v14.18.1。参考网址:https://stackoverflow.com/questions/63196042/npm-does-not-support-node-js-v12-18-3 。进入目录:C:\Users\Administrator\AppData\Roaming\。删除 npm 和 npm-cache 文件夹。如图5

图5

6、查看 npm 的版本:6.14.15,再次更新 npm。执行命令:npm install -g npm。升级至版本:8.1.0。如图6

图6

PS E:\wwwroot\laravel-8-5> npm -v
6.14.15
PS E:\wwwroot\laravel-8-5> npm install -g npm
C:\Users\Administrator\AppData\Roaming\npm\npm -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
C:\Users\Administrator\AppData\Roaming\npm\npx -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
+ npm@8.1.0
added 220 packages from 96 contributors in 25.764s
PS E:\wwwroot\laravel-8-5> npm -v
8.1.0
PS E:\wwwroot\laravel-8-5>

7、重复第 1 步骤,安装成功,不再报错。符合预期。如图7

图7

PS E:\wwwroot\laravel-8-5> npm -v
8.1.0
PS E:\wwwroot\laravel-8-5> php artisan breeze:install
Breeze scaffolding installed successfully.
Please execute the "npm install && npm run dev" command to build your assets.
PS E:\wwwroot\laravel-8-5> composer require laravel/breeze --dev
Using version ^1.4 for laravel/breeze
./composer.json has been updated
Running composer update laravel/breeze
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/breeze
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
78 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi
No publishable resources for tag [laravel-assets].
Publishing complete.
PS E:\wwwroot\laravel-8-5> npm run devnpm install
^C终止批处理操作吗(Y/N)? Y
PS E:\wwwroot\laravel-8-5> npm install
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

changed 48 packages, and audited 813 packages in 1m

88 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
PS E:\wwwroot\laravel-8-5> npm run dev

> dev
> npm run development


> development
> mix



* Mix █████████████████████████ emitting (95%)
 emit




* Mix █████████████████████████ done (99%) plugins
 WebpackBar:done



√ Mix
  Compiled successfully in 10.53s



   Laravel Mix v6.0.34


✔ Compiled Successfully in 10214ms
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────┐
│                                                                                                      File │ Size     │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────┤
│                                                                                                /js/app.js │ 682 KiB  │
│                                                                                               css/app.css │ 3.83 MiB │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────┘

* Mix █████████████████████████ cache (99%)
 begin idle

webpack compiled successfully
PS E:\wwwroot\laravel-8-5> php artisan migrate
Nothing to migrate.
PS E:\wwwroot\laravel-8-5>
永夜