个性化阅读
专注于IT技术分析

解决问题:ERROR in .~babel-loaderlib!.~vue-loaderlibselector.jstype=script&index=0!.srcApp.vue Module not found Error Can’t resolve ‘.componentsNavbar’

当导入一个没有.vue扩展名的vue文件时,会出现以下错误:

ERROR in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue Module not found: Error: Can't resolve './components/Navbar'

Webpack配置如下:

module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            // Since sass-loader (weirdly) has SCSS as its default parse mode, we map
            // the "scss" and "sass" values for the lang attribute to the right configs here.
            // other preprocessors should work out of the box, no loader config like this necessary.
            'scss': 'vue-style-loader!css-loader!sass-loader',
            'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax'
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  },
  resolve: {

    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },

问题解决办法

方式一

该错误是由于webpack的配置,要使Webpack自动解析.vue扩展,请使用resolve.extensions选项,并包含默认值,如下:

resolve: {
    extensions: ['*', '.js', '.vue', '.json']
}

方式二

通过在Webpack解析中包含扩展数组,使Webpack自动解析.vue扩展,如下:

resolve: {
    extensions: ['.vue'],
   },
赞(0)
未经允许不得转载:srcmini » 解决问题:ERROR in .~babel-loaderlib!.~vue-loaderlibselector.jstype=script&index=0!.srcApp.vue Module not found Error Can’t resolve ‘.componentsNavbar’

评论 抢沙发

评论前必须登录!