Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get following error when I import *.vue files without .vue extension?

I get following error when I import a vue file without .vue extension .

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'

My web back configuration is as below

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'
    }
  },
like image 925
CuriousGuy Avatar asked May 31 '17 17:05

CuriousGuy


People also ask

What is .Vue extension?

VUE file extension is mainly associated with single file components used by Vue, an open-source, frontend JavaScript framework for building user interfaces. Such VUE single-file components are modules containing source code (typically for a single UI component) which can be exported or reused in a Vue application.

How do I import a Vue file into JavaScript?

There are two ways to import a JavaScript library to the Vue Component. The first is to import a local JavaScript library. Here, you can import the JavaScript library by using the 'import' keyword inside the script tag of your Vue file. import * as mykey from '../assets/js/mykey.

Does Vue require Webpack?

Vue CLI is built on top of Webpack and so for beginners, you do not need to know what Webpack is as the Vue CLI has taken care of the configurations with great default presets and you literally need 0 configs to start.


1 Answers

The problem is in your Webpack configuration. To make Webpack automatically resolve .vue extensions use the resolve.extensions option, and include the defaults.

resolve: {
    extensions: ['*', '.js', '.vue', '.json']
}
like image 60
Nick M Avatar answered Sep 28 '22 19:09

Nick M