I cannot bundle ipfs-core with webpack. Module not found: Error: Can’t resolve ‘util’
I cannot bundle ipfs-core with webpack. Module not found: Error: Can’t resolve ‘util’
我想在我的应用程序的浏览器端使用 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 }}
};
好的,我找到了解决方案。 webpack 5+ 需要这个 module 用于 polyfills。
我想在我的应用程序的浏览器端使用 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 }}
};
好的,我找到了解决方案。 webpack 5+ 需要这个 module 用于 polyfills。