简体   繁体   English

在 webpack 中包含 polyfills > 5 在 CRA

[英]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.

相关问题 CRA Webpack 依赖优化 - CRA Webpack Dependency Optimization webpack < 5 用于默认包含 node.js 核心模块的 polyfill。 这已不再是这种情况 - webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case 在 React 中使用 web3 有错误:webpack &lt; 5 used to include polyfills for node.js core modules by default - useing web3 in React has error : webpack < 5 used to include polyfills for node.js core modules by default 重大变化:webpack < 5 用于默认包含 node.js 核心模块的 polyfill(React JS、TypeScript 和 JWT) - BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default (React JS, TypeScript & JWT) Node.js webpack5 错误,找不到模块; 重大更改:webpack &lt; 5 用于包含用于 node.js 内核的 polyfill - Node.js webpack5 error, Module not found; BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core 未找到模块:错误:无法解析“crypto”,webpack < 5 默认用于包含 node.js 核心模块的 polyfill - Module not found: Error: Can't resolve 'crypto', webpack < 5 used to include polyfills for node.js core modules by default 我想添加 web3 package 来响应项目 - BREAKING CHANGE: webpack &lt; 5 used to include polyfills for node.js core modules by default - I want to add web3 package to react project - BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default 当我添加 package 时,我收到 webpack &lt; 5 用于默认包含 node.js 核心模块的 polyfills。现在不再是这种情况 - when i add a package i recieve webpack < 5 used to include polyfills for node.js core modules by default.This is no longer the case CRA webpack - 输出单独的文件 - CRA webpack - output separate files Node Polyfills 和 webpack.config.js 的问题 - Issues with Node Polyfills and webpack.config.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM