pnpm monoreop 打包时 node_modules 内部包 typescript 不能推导出类型报错

报错信息如下:

md 复制代码
../../packages/antdv/components/pro-table/src/form-render.vue:405:1 - error TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/[email protected]/node_modules/scroll-into-view-if-needed'. This is likely not portable. A type annotation is necessary.

405 export default (await import('vue')).defineComponent({
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406 setup() {
    ~~~~~~~~~
... 
412 __typeEl: {} as __VLS_TemplateResult['rootEl'],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
413 });
    ~~~
../../packages/antdv/components/pro-table/src/form-render.vue:405:1 - error TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/[email protected][email protected][email protected]_/node_modules/vue-types'. This is likely not portable. A type annotation is necessary.

405 export default (await import('vue')).defineComponent({
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406 setup() {
    ~~~~~~~~~
... 
412 __typeEl: {} as __VLS_TemplateResult['rootEl'],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
413 });

he inferred type of 'default' cannot be named without a reference to '.pnpm/[email protected]/node_modules/scroll-into-view-if-needed'. This is likely not portable. A type annotation is necessary.

看了一下lock文件,scroll-into-view-if-needed,vue-types这两个依赖主要是ant-design-vue使用的,为什么会报错呢,因为之前vue的版本是3.4.x,现在整到了3.5.13,降到 3.4.x就没问题了

根据这个报错搜索了一下,看到的解决方案就是把报错的包在 tsconfig.json配置一下

json 复制代码
{
  "compilerOptions": {
    "target": "ESNext",
    "jsx": "preserve",
    "jsxImportSource": "vue",
    "lib": ["ESNext"],
    "baseUrl": ".",
    "module": "ESNext",
    "moduleResolution": "Node",
    // 在这配置一下
    "paths": {
      "scroll-into-view-if-needed": ["node_modules/scroll-into-view-if-needed"],
      "vue-types": ["node_modules/vue-types"]
    },
    "resolveJsonModule": true,
    "strict": true,
    "noImplicitAny": false,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "preserveSymlinks": true,
    "skipLibCheck": true
  }
}
相关推荐
GISer_Jing11 分钟前
[总结篇]个人网站
前端·javascript
ss.li12 分钟前
TripGenie:畅游济南旅行规划助手:个人工作纪实(二十二)
javascript·人工智能·python
程序员秘密基地33 分钟前
基于vscode,idea,java,html,css,vue,echart,maven,springboot,mysql数据库,在线考试系统
java·vue.js·spring boot·spring·web app
海的诗篇_1 小时前
前端开发面试题总结-JavaScript篇(二)
开发语言·前端·javascript·typescript
琹箐1 小时前
ant-design4.xx实现数字输入框; 某些输入法数字需要连续输入两次才显示
前端·javascript·anti-design-vue
程序员-小李1 小时前
VuePress完美整合Toast消息提示
前端·javascript·vue.js
Dontla5 小时前
为什么React列表项需要key?(React key)(稳定的唯一标识key有助于React虚拟DOM优化重绘大型列表)
javascript·react.js·ecmascript
德育处主任Pro8 小时前
『React』Fragment的用法及简写形式
前端·javascript·react.js
CodeBlossom8 小时前
javaweb -html -CSS
前端·javascript·html
CodeCraft Studio8 小时前
【案例分享】如何借助JS UI组件库DHTMLX Suite构建高效物联网IIoT平台
javascript·物联网·ui