-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web3 don't work with latest of React #4659
Comments
same here, not working and getting the following:
|
Hey thanks for creating this issue. |
Thank you for read about it. It’s very strange error. I think is an issue between latest version of React and webpack and the latest version of library |
@thedarkknight197 |
Same issue here:( |
yes, using create-react-app, was able to run the dev server by installing react-app-rewired and overridong some webpack config |
my workaround is:
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"assert": require.resolve("assert"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"os": require.resolve("os-browserify"),
"url": require.resolve("url")
})
config.resolve.fallback = fallback;
return config;
} the packages need to be added (
import { Buffer } from 'buffer';
(window as any).global = window;
global.Buffer = Buffer;
global.process = {
env: { DEBUG: undefined },
version: '',
nextTick: require('next-tick')
} as any;
More info here: https://github.com/ChainSafe/web3.js#trouble-shooting-and-known-issues |
For my project already started how can i migrate to it? I will create a new project? @mseemann |
@thedarkknight197 the steps i have described were also on a new created project with npx create-react-app. |
@mseemann awesome workaround for people running with
|
So i can use npm in my proget already started with:
Right? |
In js in polyfill i need to remove the "as any" directive, but now i have this error:
I will try to add it |
Nothing:
My terminal:
|
@thedarkknight197 do you have |
I insert import './polyfill' how is told by @mseemann
|
if i move the import of polyfill on firstline of file index.js the site now is visible. But in my terminal this message don't go away:
|
The full console errors:
|
Glad the page has loaded and built succesfully, I'll see if theres anything that can be done about this warnings. |
thank you so much... I will wait any news, thank you for your patience |
@luu-alex, @thedarkknight197 to disable the warning you can add |
Great it work! :D |
Hi @thedarkknight197 Based on above discussion and specially #4659 (comment) it seems the issue is resolved. Probably its because the latest Webpack does not ship the NodeJS polyflils by default. As we are focused on If you think some points are left unresolved, feel free to reopen the issue. |
https://github.com/ChainSafe/web3.js#web3-and-create-react-app Thanks everyone :) |
just re-affirming the latest solution posted on the github repo works! |
still having same error |
Is there any workaround for vuejs applications? I am still getting this issue |
Yeah, I got it working with vuejs. All good |
I'm having the same problem as described in this thread but with a vue/vuex app. Is there a workaround for vue? I see that the above workarounds all involve installing |
Yes, I have created a sample application in vuejs and web3. Check this, specifically |
Oh perfect this worked! Thanks! |
Please share the js version of polyfill.ts |
Perfect |
…/4659\#issuecomment-1004660167 but did not do the polyfill.js file
Failed to compile. Error in ./src/index.js @ ./src/index.js 14:14-37 |
Failed to compile. Error in ./src/index.js @ ./src/index.js 16:14-37 |
same issue |
same again |
Hey there, sorry for the long wait but we are coming up with a permanent solution. Pr has been created, thanks everyone |
when polyfill file is created and imported on index.js/ts import { Buffer } from 'buffer'; (window as any).global = window; it comes with this error ERROR in ./src/polyfill.js Module build failed (from ./node_modules/babel-loader/lib/index.js): 1 | import { Buffer } from 'buffer';
|
@gmako6 Hi, we have a fix for this in the next version but if you want to get it working now you can use this. You dont need the polyfill file for this method. within your project, go to your
save it and it should work |
@luu-alex the issue is still present in every other packages, such as web3-eth-contract, web3-core, etc... importing those breaks React. |
@simlevesque are you importing these packages seperately or through the web3 package |
I succeed to solve the problem by following those steps: Uninstall Webpack 5: npm uninstall webpack delete package-lock.json Go to package.json and change from "React-scripts": "5.0.0" to "React-scripts": "4.0.3", install webpack 4: npm install webpack@4.44.2 npm install npm run start I hope it helps ;) |
still not working. Tried every solution above. |
Copy paste your package.json |
It's is best to use yarn according to my new experience it works smoothly 🫡 |
ERROR in ./node_modules/dotenv/lib/main.js 24:11-24 ERROR in ./node_modules/eth-lib/lib/bytes.js 7:193-227 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: ERROR in ./node_modules/swarm-js/node_modules/eth-lib/lib/bytes.js 9:193-227 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: ERROR in ./node_modules/web3-shh/node_modules/web3-providers-http/lib/index.js 28:11-26 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: ERROR in ./node_modules/web3-shh/node_modules/web3-providers-http/lib/index.js 30:12-28 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: ERROR in ./node_modules/web3/node_modules/web3-eth-accounts/lib/index.js 31:74-91 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: ERROR in ./node_modules/web3/node_modules/web3-providers-http/lib/index.js 28:11-26 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: ERROR in ./node_modules/web3/node_modules/web3-providers-http/lib/index.js 30:12-28 BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. If you want to include a polyfill, you need to: If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }' webpack compiled with 10 errors and 80 warnings |
{ |
@raiabdullahbashir update web3 to 1.8, u are using 1.6.1 |
@luu-alex thank you but my issue was resolved by setting "scripts": { to this "scripts": { |
Is there an existing issue for this?
Current Behavior
I have an issue with web3 with latest version of react.
It can't be imported in code.
The message is:
Expected Behavior
I am expected that the import with
import Web3 from 'web3';
still work
Steps to Reproduce
Web3.js Version
1.6.0
Environment
Anything Else?
No response
The text was updated successfully, but these errors were encountered: