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/scroll-into-view-if-needed@2.2.31/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/vue-types@3.0.2_vue@3.5.13_typescript@5.8.2_/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/scroll-into-view-if-needed@2.2.31/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
  }
}
相关推荐
姜太公钓鲸2331 天前
ROM就是程序存储器,实际的存储介质是Flash闪存。上述描述中的程序存储器是什么意思?
开发语言·javascript·ecmascript
柳杉1 天前
使用AI从零打造炫酷医疗数据可视化大屏,源码免费拿!
前端·javascript·数据可视化
简单Janeee1 天前
[Vue 3 从零到上线]-第四篇:组件化思维——把网页像积木一样拆解
javascript·vue.js·ecmascript
Heo1 天前
深入React19任务调度器Scheduler
前端·javascript·面试
一枚前端小姐姐1 天前
Vue3 + Pinia 状态管理,从入门到模块化
前端·vue.js
boooooooom1 天前
Vue3 nextTick 实现大变化:微任务优先,彻底搞懂渲染时机!
javascript·vue.js·面试
折七1 天前
NestJS 用了两年,我换了这个
typescript·node.js·nestjs
用户14436183400971 天前
你不知道的JS上-(九)
前端·javascript
Wect1 天前
LeetCode 102. 二叉树的层序遍历:图文拆解+代码详解
前端·算法·typescript
冴羽1 天前
2026 年 JavaScript 框架 3 大趋势
前端·javascript·react.js