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

monorepo: Cannot find package

Open rickyzhangca opened this issue 1 year ago • 5 comments

I have both react and react-dom installed and running the example, it gives an error saying the packages cannot be found

image

rickyzhangca avatar Nov 21 '23 23:11 rickyzhangca

I suspect that this is due to me having a monorepo...? it seems that the plugin is trying to find the packages under the root instead of apps/...

rickyzhangca avatar Nov 21 '23 23:11 rickyzhangca

我这边也有相同的问题 当package.json type指定module时会报react包找不到 当package.json删除type为默认时 报require的错误 提示Vite 的 CJS Node API 构建已经被废弃 但是插件的导入方式是esm的导入方式

MissFlower avatar Nov 22 '23 03:11 MissFlower

和monorepo没关系,我这边也遇到这个问题了 使用"react-vendor": [/react/] 代替 "react-vendor": [”react“] 就可以了

@rickyzhangca @MissFlower @sanyuan0704

lorenzohee avatar Nov 23 '23 02:11 lorenzohee

和monorepo没关系,我这边也遇到这个问题了 使用"react-vendor": [/react/] 代替 "react-vendor": [”react“] 就可以了

@rickyzhangca @MissFlower @sanyuan0704

image 这样确实好使了 不过这是命中了正则的逻辑 固定包名的逻辑应该还是有问题

我想问另一个问题 就是如果package.json的type使用默认的commonjs 插件好像走的是cjs的代码 但是插件是用esm的导入方式 image

MissFlower avatar Nov 23 '23 03:11 MissFlower

固定包名的处理,应该是 Rollup 的返回参数有所变化,亦或者是 vite 5 废弃了私有 api 的使用,使用其提供的兼容库替代后,导致原有的匹配逻辑出现问题。

主要的匹配逻辑是这两块:

  • https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/index.ts
  • https://github.com/sanyuan0704/vite-plugin-chunk-split/blob/master/src/staticImportScan.ts

ref:https://vitejs.dev/guide/migration#remove-resolvepackageentry-and-resolvepackagedata-apis

greenhat616 avatar Dec 06 '23 10:12 greenhat616