vue + webpack,系统告诉我“模块构建失败:TypeError:this._init不是函数”

时间:2017-02-10 09:47:29

标签: javascript webpack vue.js

我不知道如何修复它,我一直在搜索太多的信息,所有人告诉我我没有安装npm模块,但我的'package.json'文件已经安装了它们。

我已经安装了所有npm模块

dependencies": {
"babel-core": "^6.22.1",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"babel-runtime": "^6.22.0",
"css-loader": "^0.26.1",
"style-loader": "^0.13.1",
"vue": "^2.1.10",
"vue-hot-reload-api": "^2.0.8",
"vue-html-loader": "^1.2.3",
"vue-loader": "^10.3.0",
"vue-template-compiler": "^2.1.10",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"}

其他档案
webpack.config.js

module.exports={
entry:'./main.js',

output:{
    path:__dirname,
    filename:'build.js'
},

module:{
    loaders:[
        {test:/\.vue$/, loader:'vue'},
        {test:/\.js$/, loader:'babel-loader', exclude:/node_modules/}
    ]
}};

main.js

import Vue from 'vue'
import App from './App.vue'

new Vue({
    el:'body',
    components:{
        app:App
    }
});

App.vue

<template>
    <h1>welcome Vue</h1>
</template>

<script type="text/javascript"></script>

<style type="text/css"></style> 

和最终文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="bundle.js"></script>
</head>
<body>
<div id="app">
    <app></app>
</div>
</body>
</html>

当我启动webpack-dev-server时,shell告诉我 TypeError: this._init is not a function

(ps:我的英语不好,所以....)

我已经在'webpack.config.js'文件中解决了这个问题

{test:/\.vue$/, loader:'vue'}

更改为

{test:/。vue $ /,loader:'vue-loader'}

因为我使用的是vue 2.0版本。

1 个答案:

答案 0 :(得分:0)

webpack.config.js中的行应为全名:

{test:/\.vue$/, loader:'vue-loader'},