程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了webpack 导入 App.vue 或其他组件 vue 失败大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决webpack 导入 App.vue 或其他组件 vue 失败?

开发过程中遇到webpack 导入 App.vue 或其他组件 vue 失败的问题如何解决?下面主要结合日常开发的经验,给出你关于webpack 导入 App.vue 或其他组件 vue 失败的解决方法建议,希望对你解决webpack 导入 App.vue 或其他组件 vue 失败有所启发或帮助;

我目前正在创建一个基于 webpack 并使用 typescript 添加到 vue3。 但现在我面临的问题是 TS2307: CAnnot find module './App.vue' or its corresponding type declarations.

webpack 导入 App.vue 或其他组件 vue 失败

shsims-vue.d.ts当前设置在src文件夹下,默认生成。

/* eslint-disable */
import VueRouter,{ Route } from 'vue-router'

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

}

这是我的 tsconfig.Json


{
    "compilerOptions": {
      "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","src/shims-vue.d.ts"    ],"exclude": [
      "node_modules"
    ]
  }

这是我的 webpack 配置文件

const HTMLWebpackPlugin = require('HTML-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const { VueLoaderPlugin } = require('vue-loader')
const utils = require('./utils')
const path = require('path');

module.exports = {
    mode: 'development',entry: './src/main.ts',output: {
        path: path.resolve(__dirname,'dist'),filename: 'main.[hash].bundle.Js'
    },resolve: {
        extensions: ['.ts','.Js','.vue','.Json'],alias: {
            'vue': '@vue/runtime-dom'
        }
    },devServer: {
        contentBase: path.join(__dirname,'public'),port: 9000,hot: true
    },module: {
        rules: [
            {
                test: /\.tsx?$/,loader: 'ts-loader',options: {
                    appendTsSuffixTo: [/\.vue$/],},exclude: /node_modules/,{
                test: /\.s[ac]ss$/i,use: [MiniCSSExtractPlugin.loader,"css-loader","sass-loader"],{
                test: /\.m?Js$/,use: {
                    loader: "babel-loader"
                }
            },{
                test: /\.png/,type: 'asset/resource'
            },{
                test: /\.vue$/,use: {
                    loader: "vue-loader",}
            },]
    },// to see the source code in browser 
    devtool: 'source-map',plugins: [
        new HTMLWebpackPlugin({
            template: './public/index.HTML'
        }),new VueLoaderPlugin(),new MiniCSSExtractPlugin({
            filename: 'main.[hash].CSS'
        })
    ]
}

在其他组件中也面临此错误,不知道这是如何发生的以及如何解决。请对此有所了解。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的webpack 导入 App.vue 或其他组件 vue 失败全部内容,希望文章能够帮你解决webpack 导入 App.vue 或其他组件 vue 失败所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。