簡體   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