首页 > 解决方案 > 带有TypeScript的Vue js 3找不到模块'xxxxxx'或其相应的类型声明

问题描述

我用 vue js 2 制作了一个分页插件。在另一个项目中使用 Vue 3 和 TypeScript 时出现错误。错误消息是“找不到模块 'l-pagination' 或其相应的类型声明”。当我下载了几个不同的项目时,它们运行良好。是我正在创建的插件中的问题还是有解决此错误的不同方法('找不到模块'l-pagination'或其相应的类型声明')?

Shims-vue.d.ts

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

tsconfig.json

{
  "compilerOptions": {
    "noImplicitAny": false,
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

标签: typescriptvue.js

解决方案


添加到 tsconfig.json:

"types": ["node"]

并安装@types/node:

npm install --save-dev @types/node


推荐阅读