项目环境
C:\Users\19139>node -v
v18.16.0
C:\Users\19139>pnpm -v
8.2.0
vue3+vite4打包报错
"vue": "3.3.4",
"vite": "4.0.4",
"rollup": "^3.27.2",
报错
D:\work\demo>npm run build
> [email protected] build D:\work\demo
> vite build --mode pro
Building [████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 11% | Time: 24.7s
Build failed. Please check the error message
error during build:
SyntaxError: Error parsing JavaScript expression: Unexpected token, expected "," (3:16)
at createCompilerError (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:17:17)
at processExpression (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:3128:7)
at Object.transformOn (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:4706:23)
at transformOn (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-dom\dist\compiler-dom.cjs.prod.js:2655:23)
at buildProps (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:4366:48)
at Array.postTransformElement (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:4028:32)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1998:15)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1985:9)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at traverseChildren (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1950:5)
at traverseNode (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1992:7)
at transform (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:1888:3)
at Object.baseCompile (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-core\dist\compiler-core.cjs.prod.js:5202:3)
at Object.compile (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-dom\dist\compiler-dom.cjs.prod.js:2935:23)
at doCompileTemplate (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-sfc\dist\compiler-sfc.cjs.js:3627:47)
at Object.compileTemplate (D:\work\demo\node_modules\.pnpm\@[email protected]\node_modules\@vue\compiler-sfc\dist\compiler-sfc.cjs.js:3587:12)
at compile (D:\work\demo\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@vitejs\plugin-vue\dist\index.cjs:167:35)
at transformTemplateInMain (D:\work\demo\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@vitejs\plugin-vue\dist\index.cjs:156:18)
at genTemplateCode (D:\work\demo\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@vitejs\plugin-vue\dist\index.cjs:2441:12)
at transformMain (D:\work\demo\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@vitejs\plugin-vue\dist\index.cjs:2296:55)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `vite build --mode pro`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build 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\19139\AppData\Roaming\npm-cache\_logs\2023-08-09T01_52_18_137Z-debug.log
解决办法
找到报错的js文件,对应方法添加打印对应报错信息
打印后,重新执行 npm run build
, 报错更新图下