简体   繁体   English

VueJS/Typescript 错误:找不到模块“我的模块”或其相应的类型声明

[英]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.

相关问题 VueJS/Typescript - 找不到模块“./components/Navigation”或其相应的类型声明 - VueJS/Typescript - Cannot find module './components/Navigation' or its corresponding type declarations 打字稿 - 找不到模块......或其相应的类型声明 - Typescript - Cannot find module ... or its corresponding type declarations Lerna、yarn 和 Typescript:找不到模块或其对应的类型声明 - Lerna, yarn, and Typescript: Cannot find module or its corresponding type declarations “找不到模块'./style'或其相应的类型声明”错误,typescript linter - “Cannot find module './style' or its corresponding type declarations” error, typescript linter TS 找不到我的 vue3 模块 &#39; 或其对应的类型声明错误 - TS cannot find my vue3 module ' or its corresponding type declarations error Nuxt TypeScript 错误:nuxt:typescript 找不到模块'@/my-module' - Nuxt TypeScript error: nuxt:typescript Cannot find module '@/my-module' 找不到模块“./styles.scss”或其对应的类型声明 - Cannot find module './styles.scss' or its corresponding type declarations 找不到模块“./SLink.svelte”或其对应的类型声明 - Cannot find module './SLink.svelte' or its corresponding type declarations TS2307:找不到模块“@/*”或其对应的类型声明 - TS2307: Cannot find module '@/*' or its corresponding type declarations Heroku:使用 graphql 文件编译 Typescript 时出错 - 错误 TS2307:找不到模块“graphql”或其相应的类型声明 - Heroku: error compiling Typescript with graphql files - error TS2307: Cannot find module 'graphql' or its corresponding type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM