欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

打包組件報(bào)錯(cuò):Error:Cannot?find?module?'vue/compiler-sfc'

 更新時(shí)間:2023年12月26日 10:35:32   作者:xuelong-ming  
最近遇到這樣的問(wèn)題,vue組件庫(kù)搭建過(guò)程中使用webpack打包組件時(shí)報(bào)錯(cuò),本文給大家分享打包組件報(bào)錯(cuò):Error:?Cannot?find?module?‘vue/compiler-sfc‘的解決方法,感興趣的朋友一起看看吧

vue組件庫(kù)搭建過(guò)程中使用webpack打包組件時(shí)報(bào)錯(cuò),報(bào)錯(cuò)內(nèi)容如下:

Error: Cannot find module 'vue/compiler-sfc'
Require stack:
- D:\vue2\moon-ui\node_modules\vue-loader\dist\index.js
- D:\vue2\moon-ui\webpack.config.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (D:\vue2\moon-ui\node_modules\vue-loader\dist\index.js:8:24)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\vue2\\moon-ui\\node_modules\\vue-loader\\dist\\index.js',
    'D:\\vue2\\moon-ui\\webpack.config.js'
  ]
}

發(fā)現(xiàn)報(bào)錯(cuò)文件:webpack.config.js

const path = require("path");
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const glob = require("glob");
const list = {};
?
async function makeList(dirPath, list) {
    const files = glob.sync(`${dirPath}/**/index.js`)
    for (const file of files) {
        const component = file.split(/[/.]/)[2];
        list[component] = `./${file}`;
    }
}
makeList("components/lib", list)
module.exports = {
    entry: list,
    output: {
        filename: '[name].umd.js',
        path: path.resolve(__dirname, "dist"),
        library: 'mui',
        libraryTarget: 'umd'
    },
    plugins: [
        new VueLoaderPlugin(),
    ],
    module: {
        rules: [
            {
                test: /\.vue$/,
                use: [
                    { loader: 'vue-loader' },
                ]
            }
        ]
    }
};

通過(guò)執(zhí)行下面代碼,測(cè)試當(dāng)前文件是否可執(zhí)行:

node webpack.config.js

發(fā)現(xiàn)當(dāng)引入VueLoaderPligin時(shí)報(bào)錯(cuò)

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

查詢發(fā)現(xiàn)package.json中vue-loader版本是17.0.0:

{
  ...
  "devDependencies": {
    ...
    "vue-loader": "^17.0.0",
    ...
  }
}

解決方法

npm i vue-loader@15 -D

安裝低版本的vue-loader

重新嘗試打包,解決問(wèn)題! 

到此這篇關(guān)于打包組件報(bào)錯(cuò):Error: Cannot find module ‘vue/compiler-sfc‘的文章就介紹到這了,更多相關(guān)打包組件報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論