I’m working on an NFT Minter project using React and web3.js. When I try to import the .env file in the interact.js file, I get a bunch of errors. The main issue seems to be with webpack not finding certain modules.
The errors mention problems with resolving modules like ‘stream’, ‘fs’, ‘path’, ‘crypto’, ‘assert’, ‘http’, ‘https’, and ‘os’. It looks like webpack 5 doesn’t include polyfills for these Node.js core modules by default anymore.
Has anyone run into this issue before? How can I fix these module resolution problems? I’m not sure if I need to add fallbacks or install additional packages. Any advice would be great!
hey there hugo! i’ve actually run into similar issues with webpack 5 and react before. it can be a real pain, right?
have you tried using the ‘react-app-rewired’ package? it lets you override the webpack config without ejecting from create-react-app. you could add fallbacks for those node modules in the config.override.js file.
I encountered a similar issue in my recent project. One effective solution is to use the ‘react-scripts’ package version 4.x instead of 5.x. This older version includes Node.js polyfills by default, which can resolve many of these module resolution problems without additional configuration.
To downgrade, you can modify your package.json file:
"react-scripts": "^4.0.3"
Then run npm install or yarn install to update dependencies. This approach often resolves these webpack-related issues without requiring complex rewiring or additional configuration. It’s a simpler fix that might save you time and effort in the long run.
Remember to test thoroughly after making this change, as there might be some compatibility issues with other dependencies.
yo hugo, that’s a tricky one! have u considered using create-react-app with craco? it’s pretty sweet for customizing webpack without ejecting. just add a craco.config.js file and throw in some polyfills: