打包組件報(bào)錯(cuò):Error:Cannot?find?module?'vue/compiler-sfc'
vue組件庫搭建過程中使用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' },
]
}
]
}
};
通過執(zhí)行下面代碼,測試當(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
重新嘗試打包,解決問題!
到此這篇關(guān)于打包組件報(bào)錯(cuò):Error: Cannot find module ‘vue/compiler-sfc‘的文章就介紹到這了,更多相關(guān)打包組件報(bào)錯(cuò)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue打包報(bào)錯(cuò):ERROR in static/js/xxx.js from UglifyJs undefined問題
- 用electron打包vue項(xiàng)目中的報(bào)錯(cuò)問題及解決
- 關(guān)于vue3?解決getCurrentInstance?打包后線上環(huán)境報(bào)錯(cuò)問題
- 解決vue打包報(bào)錯(cuò)Unexpected token: punc的問題
- vue打包靜態(tài)資源后顯示空白及static文件路徑報(bào)錯(cuò)的解決
- vue打包npm run build時(shí)候界面報(bào)錯(cuò)的解決
- vue 解決uglifyjs-webpack-plugin打包出現(xiàn)報(bào)錯(cuò)的問題
- 解決vue打包后刷新頁面報(bào)錯(cuò):Unexpected token <
- vue-cli 打包后提交到線上出現(xiàn) "Uncaught SyntaxError:Unexpected token" 報(bào)錯(cuò)
相關(guān)文章
vue在路由中驗(yàn)證token是否存在的簡單實(shí)現(xiàn)
今天小編就為大家分享一篇vue在路由中驗(yàn)證token是否存在的簡單實(shí)現(xiàn),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue結(jié)合el-upload實(shí)現(xiàn)騰訊云視頻上傳功能
這篇文章主要介紹了vue結(jié)合el-upload實(shí)現(xiàn)騰訊云視頻上傳功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
vue在頁面和方法中如何通過遍歷對象獲取對象的鍵(key)和值(value)
這篇文章主要介紹了vue在頁面和方法中如何通過遍歷對象獲取對象的鍵(key)和值(value)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
Vue3+Vite實(shí)現(xiàn)根據(jù)用戶權(quán)限的動(dòng)態(tài)路由
在現(xiàn)代前端開發(fā)中,單頁面應(yīng)用(SPA)越來越受到開發(fā)者的青睞,而 Vue.js 作為其中的一個(gè)流行框架,提供了豐富的功能來構(gòu)建用戶界面,本文將通過一個(gè)基于 Vite + Vue 3 的項(xiàng)目示例,詳細(xì)介紹如何實(shí)現(xiàn)動(dòng)態(tài)路由,有需要的可以參考下2025-10-10
vue?iview?導(dǎo)航高亮動(dòng)態(tài)設(shè)置方式
這篇文章主要介紹了vue?iview?導(dǎo)航高亮動(dòng)態(tài)設(shè)置方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05
使用vue完成微信公眾號(hào)網(wǎng)頁小記(推薦)
公司最近有一個(gè)H5頁面的功能,比較簡單的一個(gè)調(diào)查表功能,嵌套在我們微信公眾號(hào)里面。這篇文章主要介紹了使用vue完成微信公眾號(hào)網(wǎng)頁小記,需要的朋友可以參考下2019-04-04
vue-video-player 通過自定義按鈕組件實(shí)現(xiàn)全屏切換效果【推薦】
這篇文章主要介紹了vue-video-player,通過自定義按鈕組件實(shí)現(xiàn)全屏切換效果,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08
vue?頁面卡死,點(diǎn)擊無反應(yīng)的問題及解決
這篇文章主要介紹了vue?頁面卡死,點(diǎn)擊無反應(yīng)的問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10

