gpt4 book ai didi

javascript - Webpack 5 收到 Polyfill 错误?!?!我的 JavaScript React 项目在尝试编译我的 webpack.config.js 文件时收到一个 polyfill 错误

转载 作者:行者123 更新时间:2023-12-04 17:20:58 38 4
gpt4 key购买 nike

我正在学习基于 React 的 Udemy 类(class)(这是 Brad Schiff 为我们其他人准备的 React 类(class) here),我收到一个与 webpack 相关的错误,导致它无法编译。
当我试图从我正在学习的 Udemy 类(class)中编译我的 webpack 文件时,我收到以下错误...这是我在终端上收到的错误图片:
please view it here
这是错误的文本,但 请查看链接以获取更多详细信息作为屏幕截图 :

Module not found: Error: Can't resolve 'path' in '/Users/seanmodd/Development/2021/BradSchiff/Frontend/node_modules/webpack/lib/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: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./node_modules/webpack/lib/CleanPlugin.js 12:17-37
@ ./node_modules/webpack/lib/index.js 115:9-33
@ ./node_modules/dotenv-webpack/dist/index.js 12:15-33
@ ./node_modules/dotenv-webpack/browser.js 1:13-38
@ ./app/components/HomeGuest.js 5:15-40
@ ./app/Main.js 8:0-47 38:96-105

最佳答案

运行npm install node-polyfill-webpack-plugin在你的终端`
转到您的 webpack.config.js 并粘贴:

const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
module.exports = {
// Other rules like entry, output, devserver....,
plugins: [
new NodePolyfillPlugin()
]}
这应该可以解决它,他们在 webpack 5 中删除了自动 polyfill,这就是为什么降级 web3 版本也会解决它

关于javascript - Webpack 5 收到 Polyfill 错误?!?!我的 JavaScript React 项目在尝试编译我的 webpack.config.js 文件时收到一个 polyfill 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66255566/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com