[Bug Report] 使用 vant-cli 构建 vant 二开组件库,打包输出意外的类型报错
Reproduction Link
https://github.com/astfn/vant-cli-issue
Vant Version
^4.9.21
Describe the Bug
问题复现 进入 vant-kit-engineering 目录运行 build 指令, es、lib 的类型产物构建报错。
问题分析 报错信息提示我构建 multi-picker(基于 vant 二开的多选组件) 必须依赖 .pnpm/[email protected][email protected][email protected]_/node_modules/vue-router 这些。但是组件代码里面并没有引入 vue-router。 运行 pnpm why vue-router,提示👇 devDependencies: @vant/cli 7.1.0 └── vue-router 4.5.1 这个 vue-router 的版本根报错中的一样。
疑问 删除 multi-picker 组件,重新打包,不会报错,但是这个组件并没有做什么特殊处理,也没有特殊的外部依赖。同级目录下的 single-picker 能够正常打包。
具体报错信息👇 es/multi-picker/index.ts:50:7 - error TS2742: The inferred type of 'vue_sfc' cannot be named without a reference to '.pnpm/[email protected][email protected][email protected]_/node_modules/vue-router'. This is likely not portable. A type annotation is necessary.
50 const vue_sfc = /@PURE/_defineComponent({
lib/multi-picker/index.ts:50:7 - error TS2742: The inferred type of 'vue_sfc' cannot be named without a reference to '.pnpm/[email protected][email protected][email protected]_/node_modules/vue-router'. This is likely not portable. A type annotation is necessary.
50 const vue_sfc = /@PURE/_defineComponent({ ~~~~~~~~~~~
Found 2 errors in 2 files.
Errors Files 1 es/multi-picker/index.ts:50 1 lib/multi-picker/index.ts:50 error Build Type Declarations
Reproduce Steps
- pnpm i 全局依赖下载
- 分别运行 packages/utils/package.json; packages/vhooks/package.json; 中的 build 指令
- 进入 vant-kit-engineering 目录,运行 dev 可正常预览,运行 build 抛出意外的类型构建报错
- 如果删除 multi-picker 组件,即可正常打包,但是这个组件并没有什么特殊的地方
Device / Browser
No response
再提供一个信息:仓库中的 field-multi-picker 组件依赖 multi-picker,但是 field-multi-picker 打包的类型产物可以正常构建