[英]VueJS/Typescript error: Cannot find module 'my-module' or its corresponding type declarations
I have a Vue2 setup with Nuxt and Typescript.我有一个带有 Nuxt 和 Typescript 的 Vue2 设置。 I'm trying to install the vue-slick-carousel module using yarn but Typescript is giving me the error: "Cannot find module 'vue-slick-carousel' or its corresponding type declarations".
我正在尝试使用 yarn 安装vue-slick-carousel模块,但 Typescript 给了我错误:“找不到模块 'vue-slick-carousel' 或其相应的类型声明”。 Typescript newbie over here: This issue happens when I try to import the module in my component:
Typescript 新手在这里: 当我尝试在我的组件中导入模块时会发生此问题:
<script lang="ts">
import Vue from 'vue'
import { VueSlickCarousel } from 'vue-slick-carousel'
export default Vue.extend({
components: {
VueSlickCarousel
}
...
})
</script>
Contents of tsconfig.json file: tsconfig.json文件内容:
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
]
},
"types": [
"@types/node",
"@nuxt/types",
"nuxt-i18n"
]
},
"exclude": [
"node_modules",
".nuxt",
"dist"
]
}
And my vue-shim.d.ts file, not sure what to add there:还有我的 vue-shim.d.ts 文件,不确定要添加什么:
import Vue from 'vue'
declare module 'vue/types/vue' {
interface Vue {
$i18n: {
locale:string,
locales:{code:string, name:string, file:string}[]
}
}
}
I know the issue comes from Typescript not being able to find the module types.我知道问题来自 Typescript 无法找到模块类型。 I found a library called "@types/slick-carousel" that installs the types but I'm not sure what to do next.
我找到了一个名为“@types/slick-carousel”的库来安装这些类型,但我不确定下一步该做什么。 Do I need to manually define the types?
我需要手动定义类型吗?
in tsconfig.json
add @types/slick-carousel
to types:在
tsconfig.json
中添加@types/slick-carousel
到类型:
"types": [
"@types/node",
"@nuxt/types",
"nuxt-i18n",
"@types/slick-carousel"
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.