繁体   English   中英

如何在不弹出的情况下将 WebPack polyfill 添加到使用 React Create App 创建的 React App?

[英]How do I add WebPack polyfill to React App created with React Create App without ejecting?

我有一个反应应用程序,我正在尝试使用一个库,它给我这些错误:

ERROR in ./node_modules/esm/esm.js 30:10-27
Module not found: Error: Can't resolve 'module' in '.../node_modules/esm'
 @ ./node_modules/beer-color/index.js 3:10-24

ERROR in ./node_modules/esm/esm.js 33:4-17
Module not found: Error: Can't resolve 'vm' in '.../node_modules/esm'

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: { "vm": require.resolve("vm-browserify") }'
    - install 'vm-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "vm": false }
 @ ./node_modules/beer-color/index.js 3:10-24

看来我需要向 WebPack 添加一个 polyfill。我怎样才能做到这一点而不必弹出所有设置?

 yarn add react-app-polyfill core-js
然后,在与 index.js 相同的目录中手动创建 polyfills.js

导入“./polyfills”; // 索引.js

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM