react项目vite报错:UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='

发布时间 2023-12-01 22:37:25作者: FacingScreen

问题:

vite报错:UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='

今天clone一个vite的项目,安装依赖后运行npm run dev报错:

UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
at Loader.moduleStrategy (internal/modules/esm/translators.js:145:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8744) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

......

看了半天不明所以,搜索后也没发现靠谱方案,之前在别的机器上是能正常运行,想到可能是nodejs(v12)版本低的问题

解决:

升级nodejs(到v18)再运行,果然问题解决。