【发布时间】:2023-03-09 06:25:01
【问题描述】:
我正在运行一个 Gatsby3 网站,并且像许多人一样,当我尝试使用某些 web3 插件时,我遇到了关于缺少 Polyfills 的 Webpack 5 错误。我知道他们不再自动执行这些操作,我必须自己处理。
在尝试了我能找到的所有解决方案后,这个似乎应该可以工作,但不适合我。我猜我做错了什么/错过了什么。
这是我添加到 Gatsby 配置中的内容,用于处理“crypto”和“stream”缺少的 polyfill:
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
},
},
})
}
我确实安装了加密浏览器和流浏览器。
然而,同样的错误仍然存在:
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 }
- Crypto 出现上述相同错误。
感谢任何帮助!提前谢谢你。
【问题讨论】:
-
这是您的完整
onCreateWebpackConfig实例吗?你也可以分享你的package.json吗?
标签: node.js webpack gatsby web3 polyfills