@vue/cli4升級(jí)@vue/cli5?node.js?polyfills錯(cuò)誤的解決方式
一、錯(cuò)誤描述
因前端項(xiàng)目做的少,今天用 vue腳手架創(chuàng)建項(xiàng)目選擇了 @vue/cli 5.0 版本,在編譯項(xiàng)目時(shí)出現(xiàn)如下錯(cuò)誤:
二、錯(cuò)誤日志
1、日志內(nèi)容:
錯(cuò)誤1:
error in ./node_modules/jwa/index.js
Module not found: Error: Can't resolve 'crypto' in 'H:\iWork\產(chǎn)品代碼\前端代碼\ui_2\node_modules\jwa'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
錯(cuò)誤2:
error in ./node_modules/jwa/index.js
Module not found: Error: Can't resolve 'util' in 'H:\iWork\產(chǎn)品代碼\前端代碼\ui_2\node_modules\jwa'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }
錯(cuò)誤3:
error in ./node_modules/jws/lib/data-stream.js
Module not found: Error: Can't resolve 'stream' in 'H:\iWork\產(chǎn)品代碼\前端代碼\ui_2\node_modules\jws\lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
2、錯(cuò)誤原因
因?yàn)?@vue/cli 從 4.0 升級(jí)到 5.0 已經(jīng)不默認(rèn)包含 node.js 的核心 polyfills 組件了。項(xiàng)目的 package.json 的版本如下圖:
3、解決方法[可以使用的方法]
參考資料:
中文Webpack相關(guān)介紹:解析(Resolve) | webpack 中文文檔
node-polyfill-webpack-plugin 只能在 Webpack 5+ 版本使用,相關(guān)介紹:Package - node-polyfill-webpack-plugin (npmmirror.com)
1.執(zhí)行安裝命令:npm install node-polyfill-webpack-plugin
2.進(jìn)行配置 vue.config.js
在頂行添加如下:const NodePolyfillPlugin = require('node-polyfill-webpack-plugin') 在 defineConfig 中添加節(jié)點(diǎn)如下: configureWebpack: { resolve: { alias: {}, fallback: { //其他的如果不啟用可以用 keyname :false,例如:crypto:false, "crypto": require.resolve("crypto-browserify"), "stream": require.resolve("stream-browserify") }, }, plugins: [new NodePolyfillPlugin()] } 特殊說(shuō)明:fallback 內(nèi)的配置好像并未生效,不過(guò)還是推薦您寫(xiě)上你缺失的組件名。
如下圖:
4、解決辦法[存在問(wèn)題,需要研究還]
通過(guò)對(duì)日志的分析因?yàn)橛衅渌M件引用到了 polyfills 的核心組件并沒(méi)有安裝,所以報(bào)錯(cuò)了,這里需要執(zhí)行 npm install 命令進(jìn)行包安裝即可。
命令:
npm install util stream-browserify crypto-browserify
包安裝完成后 package.json 如下圖:
總結(jié)
到此這篇關(guān)于@vue/cli4升級(jí)@vue/cli5 node.js polyfills錯(cuò)誤解決的文章就介紹到這了,更多相關(guān)@vue/cli4升級(jí)@vue/cli5錯(cuò)誤內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何在Vue中實(shí)現(xiàn)登錄驗(yàn)證功能(代碼示例)
Vue是一種流行的JavaScript框架,可以幫助開(kāi)發(fā)者建立高效的Web應(yīng)用程序,本文將為您介紹如何在Vue中實(shí)現(xiàn)登錄驗(yàn)證功能,并為您提供具體的代碼示例,感興趣的朋友一起看看吧2023-11-11vue實(shí)現(xiàn)后臺(tái)管理權(quán)限系統(tǒng)及頂欄三級(jí)菜單顯示功能
這篇文章主要介紹了vue實(shí)現(xiàn)后臺(tái)管理權(quán)限系統(tǒng)及頂欄三級(jí)菜單顯示功能,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06vue使用neovis操作neo4j圖形數(shù)據(jù)庫(kù)及優(yōu)缺點(diǎn)
這篇文章主要介紹了vue使用neovis操作neo4j圖形數(shù)據(jù)庫(kù),本文給大家介紹了與常規(guī)做法的優(yōu)缺點(diǎn)對(duì)比及使用技巧,對(duì)vue?neo4j圖形數(shù)據(jù)庫(kù)相關(guān)知識(shí)感興趣的朋友一起看看吧2022-02-02Vue實(shí)現(xiàn)Echarts圖表寬高自適應(yīng)的實(shí)踐
本文主要介紹了Vue實(shí)現(xiàn)Echarts圖表寬高自適應(yīng)的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Vue2老項(xiàng)目配置ESLint和Prettier完整步驟
ESLint是一個(gè)靜態(tài)代碼分析工具,用于檢查JavaScript代碼的語(yǔ)法結(jié)構(gòu)和查找程序錯(cuò)誤,Prettier是一個(gè)代碼格式化工具,這篇文章主要給大家介紹了關(guān)于Vue2老項(xiàng)目配置ESLint和Prettier的完整步驟,需要的朋友可以參考下2024-08-08treeSelect樹(shù)組件設(shè)置父節(jié)點(diǎn)禁用的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于treeSelect樹(shù)組件設(shè)置父節(jié)點(diǎn)禁用的相關(guān)資料,文中通過(guò)圖文以及示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-12-12