1、启动客户端项目报错
当前Node.js版本:v10.13.0
启动H5项目客户端,抛如下异常:
[webpack-cli] /Users/maomao/Documents/demo/pc/askteam/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:10
static heartbeatInterval = 1000;
C02Z84E5LVCF:askteam maomao$ npm run dev
> askteam@1.0.0 dev /Users/maomao/Documents/demo/pc/askteam
> webpack server --open
[webpack-cli] /Users/maomao/Documents/demo/pc/askteam/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:10
static heartbeatInterval = 1000;
^
SyntaxError: Unexpected token =
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! askteam@1.0.0 dev: `webpack server --open`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the askteam@1.0.0 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! /Users/maomao/.npm/_logs/2022-02-16T08_38_28_460Z-debug.log
网上说是Webpack5兼容问题.
尝试切换到更低Node版本v8.17.0
又报如下错误:
[webpack-cli] You need to install 'webpack-dev-server' for running 'webpack serve'.
[webpack-cli] You need to install 'webpack-dev-server' for running 'webpack serve'.
SyntaxError: Unexpected token {
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! askteam@1.0.0 dev: `webpack server --open`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the askteam@1.0.0 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! /Users/maomao/.npm/_logs/2022-02-16T08_15_23_361Z-debug.log
2 服务端启动报错
同时本地服务端在启动的时候报如下错误:
/Users/maomao/Documents/demo/pc/askteam/server/node_modules/color/index.js:257
lum[i] = (chan <= 0.039_28) ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
^^^^^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/maomao/Documents/demo/pc/askteam/server/node_modules/colorspace/index.js:3:13)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! otp_web_module_design@0.0.1 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the otp_web_module_design@0.0.1 start 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! /Users/maomao/.npm/_logs/2022-02-16T08_53_25_074Z-debug.log
莫名其妙的错,也不知道怎么解决。
关键是之前都能正常启动。
所以我怀疑是本地Node版本问题。
解决办法
以上问题统一解决方案为,将Node.js
版本更新到最新。
C02Z84E5LVCF:server maomao$ nvm ls
-> v8.17.0
v10.13.0
v10.23.0
v16.14.0
default -> 8.17.0 (-> v8.17.0)
node -> stable (-> v16.14.0) (default)
stable -> 16.14 (-> v16.14.0) (default)
iojs -> N/A (default)
lts/* -> lts/gallium (-> v16.14.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.10 (-> N/A)
lts/fermium -> v14.19.0 (-> N/A)
lts/gallium -> v16.14.0
我当前最新版本是v16.14.0
,所以切换或安装到v16.14.0
版本即可。
切换版本:
nvm use v16.14.0
安装版本(需要外网):
nvm i v16.14.0
暂无评论