Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cssmagic opened this issue May 8, 2024 · 2 comments
Open

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

cssmagic opened this issue May 8, 2024 · 2 comments

Comments

@cssmagic
Copy link

cssmagic commented May 8, 2024

环境

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/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/lib/errors.js:436:11)
    at new NodeError (file:///path/to/my/project/node_modules/.pnpm/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/lib/errors.js:380:5)
    at packageResolve (file:///path/to/my/project/node_modules/.pnpm/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/lib/resolve.js:1035:9)
    at moduleResolve (file:///path/to/my/project/node_modules/.pnpm/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/lib/resolve.js:1113:18)
    at defaultResolve (file:///path/to/my/project/node_modules/.pnpm/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/lib/resolve.js:1289:15)
    at resolve (file:///path/to/my/project/node_modules/.pnpm/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/index.js:32:12)
    at resolveEntry (file:///path/to/my/project/node_modules/.pnpm/vite-plugin-chunk-split@0.5.0_vite@5.2.11_@types+node@20.12.8_sass@1.76.0_/node_modules/vite-plugin-chunk-split/dist/index.mjs:53:10)
    at file:///path/to/my/project/node_modules/.pnpm/vite-plugin-chunk-split@0.5.0_vite@5.2.11_@types+node@20.12.8_sass@1.76.0_/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/vite-plugin-chunk-split@0.5.0_vite@5.2.11_@types+node@20.12.8_sass@1.76.0_/node_modules/vite-plugin-chunk-split/dist/index.mjs:67:62)

临时解决

把配置修改为:

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

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


感谢关注!

@cssmagic
Copy link
Author

cssmagic commented May 8, 2024

duplicate of #33

@HongJian-Yang
Copy link

me to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants