11

i am still practicing to use webpack2 with vue js and babel but bumped to this error. i don't know what exactly is missing.

ERROR in ./src/main.js 
Module not found: Error: Can't resolve './app/index.vue' in 'E:\xampp\htdocs\webpack-practice\src'
@ ./src/main.js 3:0-43

it seems the error is coming from the line i try to import vue component here

//file src\main.js
import Vue from 'vue'

import AppComponent from './app/index.vue'

const vm = new Vue({
el: '#app',
components: {
    app: AppComponent,
},
render: h => h('app'),
})

this is my config file

//file webpack.config.js
var webpack = require('webpack');
module.exports = {
entry: './src/main',
output: {
    path: './build',
    filename: 'main.js',
},
module: {
    rules: [
    {
        test: /\.vue$/,
        use: { 
            loader: 'vue'               
        }
    },
    {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader'
    }
    ]
},
plugins: [
    new webpack.LoaderOptionsPlugin({
        vue: {
            loader: {
                js: 'babel-loader'
            }
        }
    })
]
}

i'm pretty sure the import path is valid, here is my folder structure. and already put ./ prefix before the folder name.

 root
 |----index.html
 |----webpack.config.js
 |----app
 |     |----index.vue
 |     |----some file
 |
 |----build
 |     |----main.js
 |
 |----node_modules
 |
 |----src
       |----main.js

what am i missing here? please help, i'm using windows 10 if it's matter.

3
  • 3
    In such case you can answer your own question to make sure that people with similar problems can use the question and answer to resolve them Commented Mar 16, 2017 at 8:50
  • Please rollback the edit to your question and instead post the solution as an answer Commented Mar 17, 2017 at 5:28
  • done. i hope i did it properly Commented Mar 17, 2017 at 7:38

4 Answers 4

19

i have solved my problem, since it seems i can't delete the answer. i'll edit how i solve the problem.

change this part

import AppComponent from './app/index.vue'

to

import AppComponent from '../app/index.vue'

i feel ashame to miss this kind of error.

and change the vue loader after the next error is appear

loader: 'vue'

changed to

loader: 'vue-loader'

then install others needed dependencies suggested by the terminal.

Sign up to request clarification or add additional context in comments.

Comments

3

your code :

  import AppComponent from './app/index.vue'

convert to :

import AppComponent from '../app/ index.vue'

OR

import AppComponent from '@/app/ index'

After run:

 npm run dev

Comments

2

I do not know which version you are using, but the following attempts should work -all of them, under the assumption you export Index.vue with name: AppComponent :

import AppComponent from './app/index'
import AppComponent from '~/app/index'
import AppComponent from '@/app/index'

Comments

1

This problem is very simple to solve and there are many solutions to it, i am going to present two:

  1. install/ reinstall vue-template-compiler and vue-loader npm packages.
  2. if the first solution does not work it means you have many broken or misconfigured npm packages, so run npm install so that it provides warning about all packages that should be installed but could not be, then install these packages and run npm install to see if everything is okay, if not install again the missing/broken packages, repeat the process until all the necessary packages are intalled.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.