简体   繁体   English

VueJS/Typescript - 找不到模块“./components/Navigation”或其相应的类型声明

[英]VueJS/Typescript - Cannot find module './components/Navigation' or its corresponding type declarations

When I create a script as typescript (lang="ts") I get an error stating当我将脚本创建为打字稿 (lang="ts") 时,我收到一条错误消息

"Cannot find module './components/Navigation' or its corresponding type declarations (Vetur 2307).". “找不到模块‘./components/Navigation’或其相应的类型声明(Vetur 2307)。”。

I realized that this only happens when I set the lang as ts, which is what I need to build my Vue application.我意识到这只有在我将 lang 设置为 ts 时才会发生,这是我构建 Vue 应用程序所需要的。

app.vue应用程序

<template>
  <Navigation />
</template>

<script lang="ts">
import Navigation from './components/Navigation'; // This is where I get the error message

export default {
  name: 'app',
  components: {
    Navigation,
  }
}
</script>

Navigation.vue导航.vue

<template>
  <div id="nav">
    <router-link to="/">Home</router-link> 
    <router-link to="/about">About</router-link> 
    <router-link to="/categories">Categories</router-link> 
    <router-link to="/random">Random</router-link>
  </div>
  <router-view />
</template>

<script lang="ts">
export default {
  name: 'Navigation',
}
</script>

In the src folder add the file shims-vue.d.ts with the following content :src文件夹中添加文件shims-vue.d.ts ,内容如下:

Vue 2 :视图 2:

declare module "*.vue" {
  import Vue from 'vue'
  export default Vue
}

Vue 3:视图 3:

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

and import the component with its extension .vue :并使用其扩展名.vue导入组件:

 import Navigation from './components/Navigation.vue';

instead of :代替 :

import Navigation from './components/Navigation';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到模块“@react-navigation/native”或其相应的类型声明 - Cannot find module '@react-navigation/native' or its corresponding type declarations ReScript,TypeScript:找不到模块“@rescript/react/src/ReactDOM.gen”或其相应的类型声明 - ReScript, TypeScript: Cannot find module '@rescript/react/src/ReactDOM.gen' or its corresponding type declarations 找不到模块“graphql-hooks”或其相应的类型声明 - Cannot find module 'graphql-hooks' or its corresponding type declarations 找不到模块“./App.svelte”或其对应的类型声明 - Cannot find module './App.svelte' or its corresponding type declarations 如何解决找不到找不到模块'../home/featuredRooms'或其对应的类型声明。? - how to solve cannot find Cannot find module '../home/featuredRooms' or its corresponding type declarations.? React,Storybook - TS2307:找不到模块“按钮”或其相应的类型声明 CAN SB RESOLVE? - React,Storybook - TS2307: Cannot find module 'Button' or its corresponding type declarations CAN SB RESOLVE? Docker/Next js:: 找不到模块“@mui/x-date-pickers/AdapterDateFns”或其相应的类型声明 - Docker/Next js :: Cannot find module '@mui/x-date-pickers/AdapterDateFns' or its corresponding type declarations 为什么我收到此错误找不到模块“nestjs/common”或其相应的类型声明 - Why I got this error Cannot find module 'nestjs/common' or its corresponding type declarations React Native Typescript babel-plugin-module-resolver 错误:找不到模块或其对应的类型声明 - React Native Typescript babel-plugin-module-resolver error: Cannot find module or its corresponding type declerations 在 vercel 上部署我的 next.js 项目,找不到模块“react-icons/Fa”或其相应的类型声明 - deploy my next.js project on vercel, Cannot find module 'react-icons/Fa' or its corresponding type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM