Vue 3:TypeError:compiler.parseComponent 不是函数

use*_*108 7 node.js webpack vue.js

我似乎无法摆脱这个错误。

我试过删除package-lock.json&node_modules后跟npm install,但是,它不起作用。

  • 节点版本: 12.18.3
  • NPM 版本: 6.14.8

任何帮助表示赞赏!


可爱的错误

ERROR in ./src/scripts/Test.vue
Module build failed (from ./node_modules/vue-loader/lib/index.js):
TypeError: compiler.parseComponent is not a function
    at parse (some path\node_modules\@vue\component-compiler-utils\dist\parse.js:15:23)
    at Object.module.exports (some path\node_modules\vue-loader\lib\index.js:67:22)
 @ ./src/scripts/app.js 8:0-30 10:10-14
Run Code Online (Sandbox Code Playgroud)

包.json

{
    "name": "app",
    "version": "1.0.0",
    "description": "",
    "private": true,
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
        "@vue/compiler-sfc": "^3.0.2",
        "vue-loader": "^15.9.4",
        "webpack": "^4.44.1",
        "webpack-cli": "^3.3.12"
    },
    "dependencies": {
        "vue": "^3.0.2"
    }
}
Run Code Online (Sandbox Code Playgroud)

webpack.config.js

const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    mode: 'development',
    entry: './src/scripts/app.js',
    output: {
        filename: 'scripts/app.js'
    },
    plugins: [
        new VueLoaderPlugin()
    ],
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: [
                    {
                        loader: 'vue-loader',
                        options: {
                            // Fixes the "vue-template-compiler" error.
                            compiler: require('@vue/compiler-sfc')
                        }
                    }
                ]
            }
        ]
    },
    watch: true
};
Run Code Online (Sandbox Code Playgroud)

源代码/脚本/app.js

import { createApp } from 'vue';
import Test from './Test.vue';

createApp(Test).mount('#app');
Run Code Online (Sandbox Code Playgroud)

src/scripts/Test.vue

<template>
    <p>{{ message }}</p>>
</template>

<script>
    export default {
        data() {
            return {
                message: "I'm giving up!"
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

use*_*108 4

解决问题的步骤:

  1. 升级vue-loader^16.0.0-beta.9
  2. 改成。const VueLoaderPlugin = require('vue-loader/lib/plugin');const { VueLoaderPlugin } = require('vue-loader');