我仍在练习将 webpack2 与 vue js 和 babel 一起使用,但遇到了这个错误。我不知道到底缺少什么。
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
似乎错误来 self 尝试在此处导入 vue 组件的行
//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'),
})
这是我的配置文件
//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'
}
}
})
]
}
我很确定导入路径有效,这是我的文件夹结构。并且已经在文件夹名称前放置了 ./前缀。
root
|----index.html
|----webpack.config.js
|----app
| |----index.vue
| |----some file
|
|----build
| |----main.js
|
|----node_modules
|
|----src
|----main.js
我在这里错过了什么?请帮忙, 如果重要的话,我正在使用 Windows 10。
最佳答案
我已经解决了我的问题,因为我似乎无法删除答案。我将编辑解决问题的方法。
改变这部分
import AppComponent from './app/index.vue'
到
import AppComponent from '../app/index.vue'
我为错过这种错误感到羞愧。
并在下一个错误出现后更改vue loader
loader: 'vue'
改为
loader: 'vue-loader'
然后安装终端建议的其他需要的依赖项。
关于javascript - 找不到模块 : Error: Can't resolve './app/index.vue' vue. js 组件导入 ES6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42828484/