I’m following the react-moralis intro and getting errors about failure to compile.
I make some simple changes to set my code up this way:
import { MoralisProvider } from 'react-moralis'
// ...other imports here...
function App() {
return (
<MoralisProvider appId={...} serverUrl={...}>
<>Previously existing code here</>
</MoralisProvider>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
But on the frontend I get this error:
Failed to compile.
Module not found: Can't resolve 'stream' in 'some_path/node_modules/cipher-base'
node_modules/cipher-base/index.js
In my webpack output, I see about a dozen errors that looks like this:
WARNING in ./node_modules/crypto-js/core.js 43:22-39
Module not found: Error: Can't resolve 'crypto' in '/Users/craig/Code/zombie-group/nft-grab-web/node_modules/crypto-js'
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 }
@ ./node_modules/crypto-js/aes.js 4:37-54
@ ./node_modules/moralis/lib/browser/CryptoController.js 9:6-30
@ ./node_modules/moralis/lib/browser/Parse.js 37:47-76
@ ./node_modules/moralis/index.js 1:0-50
@ ./node_modules/react-moralis/lib/index.esm.js 2:0-34 291:15-32 313:44-56 437:45-70 484:38-50 540:45-63 593:45-64 606:38-58 629:30-50 729:45-58 777:38-58 875:26-38 894:45-64 944:106-113 965:20-33 1136:35-56 1184:31-46 1184:50-65 1194:41-69 1211:41-62
@ ./src/app.tsx 5:0-48 17:27-42
How can I fix this? Does react-moralis
need to be updated for Webpack 5 or something?