Web3js

找不到模組:錯誤:無法解析“/Users/user/Desktop/esample/react-minting-website/node_modules/eth-lib/lib”中的“crypto”

  • June 15, 2022

在此處輸入圖像描述 這是更改反應腳本版本後的新錯誤

我正在建構一個開發 web 3 項目,但不知道為什麼會出現此錯誤

WARNING in src/App.js
 Line 2:10:  'useWeb3React' is defined but never used            no-unused-vars
 Line 4:8:   'web3' is defined but never used                    no-unused-vars
 Line 6:7:   'WalletConnect' is assigned a value but never used  no-unused-vars

ERROR in ./node_modules/eth-lib/lib/bytes.js 9:193-227
Module not found: Error: Can't resolve 'crypto' in '/Users/user/Desktop/esample/react-minting-website/node_modules/eth-lib/lib'

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: { "crypto": require.resolve("crypto-browserify") }'
       - install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
       resolve.fallback: { "crypto": false }

我附上兩張圖片。我該如何解決這個錯誤?提前致謝。 在此處輸入圖像描述

嘗試將 react-scripts 更改為 4.0.3 版本,然後嘗試

看看這個 Moralis 論壇,我認為這可能會對你有所幫助 - https://forum.moralis.io/t/solved-break-change-webpack-5-used-to-include-polyfills-for-node-js-core -modules-by-default/6875

引用自:https://ethereum.stackexchange.com/questions/130171