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
  }
}
相关推荐
JIngJaneIL44 分钟前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
敲敲了个代码1 小时前
隐式类型转换:哈基米 == 猫 ? true :false
开发语言·前端·javascript·学习·面试·web
澄江静如练_1 小时前
列表渲染(v-for)
前端·javascript·vue.js
JustHappy2 小时前
「chrome extensions🛠️」我写了一个超级简单的浏览器插件Vue开发模板
前端·javascript·github
Loo国昌2 小时前
Vue 3 前端工程化:架构、核心原理与生产实践
前端·vue.js·架构
sg_knight2 小时前
拥抱未来:ECMAScript Modules (ESM) 深度解析
开发语言·前端·javascript·vue·ecmascript·web·esm
前端白袍2 小时前
Vue:如何实现一个具有复制功能的文字按钮?
前端·javascript·vue.js
new code Boy3 小时前
escape谨慎使用
前端·javascript·vue.js
奶球不是球3 小时前
elementplus组件中el-calendar组件自定义日期单元格内容及样式
javascript·css·css3
傻啦嘿哟3 小时前
实战:用Splash搞定JavaScript密集型网页渲染
开发语言·javascript·ecmascript