typescript - 带有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"
]
}
解决方案
添加到 tsconfig.json:
"types": ["node"]
并安装@types/node:
npm install --save-dev @types/node
推荐阅读
- c# - 如何检查文件名是否包含整个文件名中的某些字符串值
- mysql - 错误 1506:外键尚不支持与分区 SQL 语句结合使用
- android - Android 电视不显示 Recyclerview
- excel - 我的代码不见了,excel找不到我的宏,但我可以在visual basic中看到模块
- flutter - 如何在地图颤动中将网络图像(也自定义此图像)显示为标记
- javascript - Javascript 在任何其他窗口之上打开新窗口
- asp.net - 母版页在 ASP.NET 中无法正常工作
- php - 将 HTML 表导出到 xlsx 会导致 INVALID_CHARACTER_ERR
- javascript - 如何将 html 数据绑定到 vuejs 和 typescript 中的对象
- java - java - 如何在java api中使用solr 7.7.2索引windows文件夹中的txt文件?