【vite】启动项目时报错:Cannot find module ‘worker_threads‘

启动新clone的vue3+vite项目时报如下错误:Cannot find module ‘worker_threads’

Error: Cannot find module 'worker_threads'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/zhaojingjing/work/hnwe/websitenew/node_modules/vite/dist/node/chunks/dep-9c153816.js:25:20)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `cross-env NODE_ENV=production vite`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

在查阅相关资料时发现vite官网有这样一段话:
【vite】启动项目时报错:Cannot find module ‘worker_threads‘_第1张图片

使用vite时node版本应为14.6.0以上

node -v查询了本地node版本为10.15.1,遂升级node版本后重新启动,解决!

附:mac系统下升级node版本

你可能感兴趣的:(vue,vue3,前端,node.js,vue)