编译简单的Vue文件时Webpack引发错误

时间:2019-06-11 13:06:02

标签: typescript vue.js webpack

当我在VS2017任务运行器中运行webpack watch时,会引发此错误:

ERROR in ./wwwroot/js/src/App.vue
Module build failed: SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (****\node_modules\vue-loader\index.js:1:80)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at loadLoader (****\node_modules\loader-runner\lib\loadLoader.js:18:17)
at iteratePitchingLoaders (****\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (****\node_modules\loader-runner\lib\LoaderRunner.js:365:2)
at NormalModule.doBuild (****\node_modules\webpack\lib\NormalModule.js:182:3)
at NormalModule.build (****\node_modules\webpack\lib\NormalModule.js:275:15)
at Compilation.buildModule (****\node_modules\webpack\lib\Compilation.js:157:10)
at factoryCallback (****\node_modules\webpack\lib\Compilation.js:348:12)
at ****\node_modules\webpack\lib\NormalModuleFactory.js:243:5
at ****\node_modules\webpack\lib\NormalModuleFactory.js:94:13
at ****\node_modules\tapable\lib\Tapable.js:268:11
at NormalModuleFactory.<anonymous> (****\node_modules\webpack\lib\CompatibilityPlugin.js:52:5)
at NormalModuleFactory.applyPluginsAsyncWaterfall (****\node_modules\tapable\lib\Tapable.js:272:13)
at ****\node_modules\webpack\lib\NormalModuleFactory.js:69:10
at ****\node_modules\webpack\lib\NormalModuleFactory.js:196:7
at nextTickCallbackWith0Args (node.js:452:9)
at process._tickCallback (node.js:381:13)

App.vue文件是一个简单的测试文件:

<template>
    <div id="app">
        <h1>XXX{{ sources.length }}</h1>
    </div>
</template>

<script>
    export default {
        name: 'app',
        data() {
            return {
                sources: []
            }
        }
    }
</script>

<style>
    #app {
        font-family: 'Avenir', Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #2c3e50;
        margin-top: 60px;
    }

    h1, h2 {
        font-weight: normal;
    }

    ul {
        list-style-type: none;
        padding: 0;
    }

    li {
        display: inline-block;
        margin: 0 10px;
    }

    a {
        color: #42b983;
    }
</style>

这在另一台机器上可以正常工作,所以我不明白为什么会引发此错误。我不太熟悉webpack / vue / typescript等,希望能有所帮助。错误消息没有用。

1 个答案:

答案 0 :(得分:0)

更新vue-loader模块成功了,通过任务运行程序仍显示错误,当在webshel​​l中运行webpack --watch --color时,它正在正确构建:

npm install vue-loader@14.2.2

https://github.com/vuejs/vue-loader/issues/1177

... Visual Studio中的问题是Task Runner正在使用node_modules / .bin文件夹中的webpack。要解决此问题,请转到工具->选项->项目和解决方案-> Web软件包管理,然后将$(PATH)条目移到列表顶部(按照Task Runner Configuration Missing in Visual Studio 2017