简体   繁体   English

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

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

I have a react App and I'm trying to use a library which gives me these errors:我有一个反应应用程序,我正在尝试使用一个库,它给我这些错误:

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

It seems I need to add a polyfill to WebPack. How can I do this without having to eject all settings?看来我需要向 WebPack 添加一个 polyfill。我怎样才能做到这一点而不必弹出所有设置?

 yarn add react-app-polyfill core-js
Then, create polyfills.js manually on the same directory with index.js 然后,在与 index.js 相同的目录中手动创建 polyfills.js

import './polyfills';导入“./polyfills”; // index.js // 索引.js

暂无
暂无

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

相关问题 有没有办法在不弹出的情况下为 create-react-app 更改 webpack 的 eslint - Is there a way to change the eslint of the webpack for the create-react-app without ejecting 如何在不弹出的情况下将 Webpack 模块联合插件与 create-react-app 一起使用 - How to use Webpack Module Federation plugin with create-react-app without ejecting 如何在不弹出的情况下压缩create react app中的构建文件? - How to compress build files in create react app without ejecting? create-react-app 使用自定义 service worker 而不弹出 - create-react-app use custom service worker without ejecting 我可以在不弹出的情况下更改 create-react-app 中公共文件夹的名称吗? - Can I change the name of the public folder in create-react-app without ejecting? 如何将 GoogleChromeLabs input-first-delay polyfill 添加到 React 应用程序 - How to add the GoogleChromeLabs input-first-delay polyfill to a React app 我怎样才能将对话框和polyfill集成到我的React应用程序中? - How can I Integrate dialog-polyfill into my React app? 如何为使用 create-react-app 创建的 react 项目更新 webpack 配置? - How to update webpack config for a react project created using create-react-app? 将React Webpack应用程序(不是使用create-react-app创建)部署到Github页面 - Deploying a React Webpack app (not created with create-react-app) to Github pages 如何在使用create-react-app创建的应用程序中将API与访问令牌一起使用 - How do I use APIs with access tokens in apps created with create-react-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM