[英]Include polyfills in webpack > 5 in CRA
I'm trying to use an NPM package called "libsodium-wrappers" inside a browser with React using Create React App, but getting the following error:我正在尝试在带有 React 的浏览器中使用 Create React App 使用名为“libsodium-wrappers”的 NPM package,但出现以下错误:
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 }
After searching the web about this, I found that I may downgrade the "react-scripts" to version 4, but I really don't want to do this, as I will need to reinstall everything and this may break things.在搜索 web 关于这个之后,我发现我可能会将“react-scripts”降级到版本 4,但我真的不想这样做,因为我需要重新安装所有东西,这可能会破坏事情。
Are there any working solutions to this besides the above one?除了上述解决方案之外,还有其他可行的解决方案吗?
Thanks谢谢
It may be related to a component library you may be using.它可能与您可能正在使用的组件库有关。 I came across you question while attempting to address this very same issue.
我在尝试解决同样的问题时遇到了您的问题。 I'm usingreact-bootstrap-table2 in a project that is causing this issue for me.
我在一个对我造成此问题的项目中使用react-bootstrap-table2 。 I believe I may have resolved it by installing the events package (specifically for react-bootstrap-table2's needs. In this case maybe try this:
我相信我可能已经通过安装事件 package 解决了这个问题(专门针对 react-bootstrap-table2 的需求。在这种情况下,可以试试这个:
yarn add path -D
Hopefully in this case that may "bump" the needle in a positive direction for you.希望在这种情况下,这可能会为你“撞”上一个积极的方向。
Do yarn add util
(alternatively, npm install util
).做
yarn add util
(或者, npm install util
)。 It worked for me.它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.