打包組件報錯:Error:Cannot?find?module?'vue/compiler-sfc'
vue組件庫搭建過程中使用webpack打包組件時報錯,報錯內(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)報錯文件: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' },
]
}
]
}
};
通過執(zhí)行下面代碼,測試當(dāng)前文件是否可執(zhí)行:
node webpack.config.js
發(fā)現(xiàn)當(dāng)引入VueLoaderPligin時報錯
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
重新嘗試打包,解決問題!
到此這篇關(guān)于打包組件報錯:Error: Cannot find module ‘vue/compiler-sfc‘的文章就介紹到這了,更多相關(guān)打包組件報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue打包報錯:ERROR in static/js/xxx.js from UglifyJs undefined問題
- 用electron打包vue項目中的報錯問題及解決
- 關(guān)于vue3?解決getCurrentInstance?打包后線上環(huán)境報錯問題
- 解決vue打包報錯Unexpected token: punc的問題
- vue打包靜態(tài)資源后顯示空白及static文件路徑報錯的解決
- vue打包npm run build時候界面報錯的解決
- vue 解決uglifyjs-webpack-plugin打包出現(xiàn)報錯的問題
- 解決vue打包后刷新頁面報錯:Unexpected token <
- vue-cli 打包后提交到線上出現(xiàn) "Uncaught SyntaxError:Unexpected token" 報錯
相關(guān)文章
vue 使用lodash實現(xiàn)對象數(shù)組深拷貝操作
這篇文章主要介紹了vue 使用lodash實現(xiàn)對象數(shù)組深拷貝操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09vue在.js文件中如何進(jìn)行路由跳轉(zhuǎn)
這篇文章主要介紹了vue在.js文件中如何進(jìn)行路由跳轉(zhuǎn),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12