我不知道如何解决它,我已经搜索了太多信息,所有人都告诉我我没有安装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
    }
});

应用程序
<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 $ /,加载程序:'vue-loader'}

因为我使用vue 2.0版本。

最佳答案

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

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

关于javascript - vue + webpack,系统告诉我 “Module build failed: TypeError: this._init is not a function”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42156190/

10-15 00:01
查看更多