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
  }
}
相关推荐
yuguo.im10 分钟前
我开源了一个 GrapesJS 插件
前端·javascript·开源·grapesjs
安且惜11 分钟前
带弹窗的页面--以表格形式展示
前端·javascript·vue.js
摘星编程1 小时前
用React Native开发OpenHarmony应用:NFC读取标签数据
javascript·react native·react.js
AGMTI3 小时前
webSock动态注册消息回调函数功能实现
开发语言·前端·javascript
码界奇点3 小时前
基于SpringBoot+Vue的前后端分离外卖点单系统设计与实现
vue.js·spring boot·后端·spring·毕业设计·源代码管理
不吃香菜的猪4 小时前
使用@vue-office/pdf时,pdf展示不全
javascript·vue.js·pdf
wuhen_n4 小时前
TypeScript的对象类型:interface vs type
前端·javascript·typescript
css趣多多4 小时前
props,data函数,computed执行顺序
前端·javascript·vue.js
一个不称职的程序猿4 小时前
构建优雅的 Vue.js 表情包选择器:一个功能丰富且可定制的 Emoji Picker 组件
前端·javascript·vue.js
无风听海4 小时前
AngularJS中$q.when()的用法
javascript·ecmascript·angular.js