我想在我的應用程式的瀏覽器端使用 ipfs-cose。我使用 webpack 作為捆綁器,但對于 ipfs-core 需要一個 polyfill
Module not found: Error: Can't resolve 'util' .......
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 }**
我嘗試了兩種建議。在resolve.fallback: { "util": require.resolve("util/") }我的網頁中匯入 ipfs-core 會引發此錯誤
Uncaught ReferenceError: process is not defined
at eval (webpack://stellarnft/./node_modules/util/util.js?:109:1)
at Object../node_modules/util/util.js (create.js:8274:1)
at __webpack_require__ (create.js:14481:42)
at eval (webpack://stellarnft/./node_modules/levelup/lib/levelup.js?:4:19)
at Object../node_modules/levelup/lib/levelup.js (create.js:3948:1)
at __webpack_require__ (create.js:14481:42)
at eval (webpack://stellarnft/./node_modules/level-packager/level-packager.js?:3:17)
at Object../node_modules/level-packager/level-packager.js (create.js:3894:1)
at __webpack_require__ (create.js:14481:42)
at eval (webpack://stellarnft/./node_modules/level/browser.js?:1:18)
resolve.fallback: { "util": false }我得到
Uncaught TypeError: inherits is not a function
at eval (webpack://stellarnft/./node_modules/levelup/lib/levelup.js?:81:1)
at Object../node_modules/levelup/lib/levelup.js (create.js:3806:1)
at __webpack_require__ (create.js:14285:42)
at eval (webpack://stellarnft/./node_modules/level-packager/level-packager.js?:3:17)
at Object../node_modules/level-packager/level-packager.js (create.js:3752:1)
at __webpack_require__ (create.js:14285:42)
at eval (webpack://stellarnft/./node_modules/level/browser.js?:1:18)
at Object../node_modules/level/browser.js (create.js:3773:1)
at __webpack_require__ (create.js:14285:42)
at eval (webpack://stellarnft/./node_modules/datastore-level/esm/src/index.js?:11:63)
這是我的 webpack 配置
module.exports = {
entry: {
wallet: './src/client/wallet.js',
account: './src/client/account.js',
topButtons: './src/client/topButtons.js',
create: './src/client/create.js',
artistInfo: './src/client/artistInfo.js'
},
output: {
filename: '[name].js',
path: __dirname '/dist/js',
},
experiments: {
topLevelAwait: true,
},
resolve: { fallback: { "util": require.resolve("util/") } }
//resolve: {fallback: { "util": false }}
};
uj5u.com熱心網友回復:
好的,我找到了解決方案。webpack 5 需要這個模塊用于 polyfills。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/448489.html
上一篇:電子“準備展示”事件未按預期作業
