vite-plugin-chunk-split icon indicating copy to clipboard operation
vite-plugin-chunk-split copied to clipboard

Node 20, Vite 5, pnpm 9 报错 `Error: Cannot find package ...`

Open cssmagic opened this issue 1 year ago • 2 comments

环境

npm create vue@latest 创建的 Vue 3 项目。环境如下:

  • macOS
  • Node.js 20.12.2
  • Vite 5.2.11
  • pnpm 9.1.0

问题

配置如下:

chunkSplitPlugin({
	strategy: 'default',
	customSplitting: {
		'vendor': ['vue'],
	}
})

运行 vite build 提示以下错误:

error during build:
Error: Cannot find package 'vue' imported from /path/to/my/project
    at __node_internal_ (file:///path/to/my/project/node_modules/.pnpm/[email protected]/node_modules/import-meta-resolve/lib/errors.js:436:11)
    at new NodeError (file:///path/to/my/project/node_modules/.pnpm/[email protected]/node_modules/import-meta-resolve/lib/errors.js:380:5)
    at packageResolve (file:///path/to/my/project/node_modules/.pnpm/[email protected]/node_modules/import-meta-resolve/lib/resolve.js:1035:9)
    at moduleResolve (file:///path/to/my/project/node_modules/.pnpm/[email protected]/node_modules/import-meta-resolve/lib/resolve.js:1113:18)
    at defaultResolve (file:///path/to/my/project/node_modules/.pnpm/[email protected]/node_modules/import-meta-resolve/lib/resolve.js:1289:15)
    at resolve (file:///path/to/my/project/node_modules/.pnpm/[email protected]/node_modules/import-meta-resolve/index.js:32:12)
    at resolveEntry (file:///path/to/my/project/node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected]_/node_modules/vite-plugin-chunk-split/dist/index.mjs:53:10)
    at file:///path/to/my/project/node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected]_/node_modules/vite-plugin-chunk-split/dist/index.mjs:67:76
    at Array.map (<anonymous>)
    at wrapCustomSplitConfig (file:///path/to/my/project/node_modules/.pnpm/[email protected][email protected]_@[email protected][email protected]_/node_modules/vite-plugin-chunk-split/dist/index.mjs:67:62)

临时解决

把配置修改为:

chunkSplitPlugin({
	strategy: 'default',
	customSplitting: {
		'vendor': [/\/vue\//],
	}
})

可以正常打包。但不确定有什么不良后果。


感谢关注!

cssmagic avatar May 08 '24 09:05 cssmagic

duplicate of #33

cssmagic avatar May 08 '24 09:05 cssmagic

me to

HongJian-Yang avatar Jul 20 '24 08:07 HongJian-Yang