-
Notifications
You must be signed in to change notification settings - Fork 5.1k
web3 does not work with webpack unless I manually install with --unsafe-perm=true #1969
Comments
Hi, I am having the same error when building for production in the pipelines.
I am hoping someone can help solve this. |
@simodroussi do you know what OS you're using for your production build process? |
we are using Amazon Linux https://hub.docker.com/_/amazonlinux/
|
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This issue now has a funding of 150.0 DAI (150.0 USD @ $1.0/DAI) attached to it.
|
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Work has been started. These users each claimed they can complete the work by 3 months, 3 weeks ago. 1) sundar-balaji has been approved to start work. I have the solution for this issue. This is permission related issue. I can help you out with this issue and resolve it asap Learn more on the Gitcoin Issue Details page. |
Hey @sUndar-Balaji feel free to give it a shot :) |
I'll post further details for more clarity and to help recreate this issue. My server-side code is a serverless project using the serverless-webpack plugin. Here are my devDependencies...
My client-side code is a create-react-app generated codebase, which uses webpack under the hood. My CI job uses the CircleCI docker image Please let me know if I can provide any further details. |
you have to set "npm config set unsafe-perm true" or you have to change the ownership of the location where you are installing the npm packages like this "sudo chown -R $USER:$USER /opt/" Pls try these options and let me know |
I have setup a react project using create-react-app and CI for that in circle CI. I have installed web3 in the react project and imported the same in the project. It's able to successfully build in local and also in circle CI My circle CI configurations are Environment - Linux Node Js version - 8.11 web3 version - 1.0.0-beta.35 You can fork this repo and create a project in circle CI. If you have some more steps to reproduce the issue in the above mentioned repo, pls mention that below |
@sUndar-Balaji I just tried setting |
@evbots could you pls mention while doing which operation in web3 you are getting the error? And could you share your config.yml file? |
Sure. The code fails before I can perform an operation. It fails on import. The line it fails on: I'm currently working with my serverless backend project, not my front-end project. I pulled web3 out of that. My serverless project config.yml file is (just the jobs portion):
With your example repo, have you tried running the react app after it builds? You should be able to ship the files to s3 and run access it via url. |
In the react app i have created using create-react-app, actually imports the web3 and does console.log(web3). Then i ran the app. I can be able to see the web3 constructor function in browser console and exported the same web3 to window object in the app's code itself. Are you getting this error in serverless backend app or in both front end and backend? |
@evbots the issue is because the version you are using. It's a beta version. I did face the similar kind of issue while running CI on the circle CI for the serverless project which uses serverless-webpack plugin What i did was changing from beta to stable version(like 0.20.7 most recently pushed stable version according to npm), and it worked. Pls try this out and let me know |
@sUndar-Balaji Next week I might be able to find some time to recreate this issue in the react-app, but the problem was the exact same as the nodejs run project when I first created this issue. So on my todo list is to (1) try and change directory permissions via As to your comment about the web3 version, this error is specific to |
@evbots the problem only occurs when we use web3(beta) with serverless with serverless-webpack plugin, on circle ci's Linux build environment. So the chances of ppl getting this issue might be very little. Due to which ppl may not have raised the issue. Still I'll look for more ways to find the solution. |
Ok, I decided to go ahead and recreate the issue with my react-app right now. I added web3.js to package.json using
Web3 is imported into App.js with the following line. My build fails on the
|
@evbots could you share your repo details. So I'll fork that repo to fix the issue |
@sUndar-Balaji yes, here you go: https://github.com/evbots/web3-webpack-build just created it |
@sUndar-Balaji yes, i remember reading that issue when I was first battling this. I never was able to use the solution proposed at the bottom of the issue. I'm not sure if the default create-react-app webpack configuration transpiles node_modules. but from some cursory reading it doesn't seem like it does. |
@evbots fixed the issue by using the following circle ci config. Changed the npm installation directory's permission to the current user.
Updated code is available in this repo web3-webpack-build-issue-repo Feel free to fork and run it on your CI environment |
@sUndar-Balaji very nice! I will have time to apply your changes and verify tomorrow. :-D |
@sUndar-Balaji I applied your changes to my repo and the build passed. Then, I reset the package-lock using an |
@evbots While doing npm install from local machine I have created that package-lock file. It will be automatically created by npm. If you have issues, try to execute the chown and unsafe-perm commands from your local machine and generate package-lock file, then try |
@evbots which version of npm are you using? Mine is 5.6.0. There are issues in npm, which mentions |
@evbots try to remove node_modules folder, execute the chown and unsafe-perm commands from your local machine and generate package-lock file by doing npm install in local. Mostly it'll resolve your issue. conflict between 5.x and 6.x isn't gonna affect this case that much. |
@evbots i have fixed your package-lock.json issue by executing the below command in my
then you can run
It will properly generate package-lock.json file
this will create the build.Then commit the created package-lock.json file to your repo. Now your build will pass in both local machine and also in your circle ci |
@sUndar-Balaji can I ask why you are editing the owner permissions for the global I generated The only one that resulted in a passing build was the npm version 5.6.0. I have yet to figure out why other package-locks generated with other npm versions result in web3 being unable to install. To add to the intrigue, when I delete package-lock and run install only referencing package.json, the build passes. No need for I am perplexed by what is happening. One thing I have not yet tried is using yarn, and if the lock file generated by yarn produces different results. |
I think this issue might be related to #1914 |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Work for 150.0 DAI (150.0 USD @ $1.0/DAI) has been submitted by: @ceresstation please take a look at the submitted work:
|
I also get this very issue when trying to deploy google cloud functions which have web3 bundled.
tried with
All with no success.
|
I can confirm that I have tested rolled back |
This issue will be solved after the PR #2000 is merged into the 1.0 branch. |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done The funding of 150.0 DAI (150.0 USD @ $1.0/DAI) attached to this issue has been approved & issued to @sUndar-Balaji.
|
@sUndar-Balaji Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
1 similar comment
@sUndar-Balaji Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
worked for me. |
Hi web3 team,
I have tried installing various versions of web3 in my webpack projects. I get very similar errors when using webpack to bundle client-side projects and server-side projects (specifically a serverless project using the serverless-webpack plugin).
The current version I'm using is [email protected] in both my client and server-side projects.
Client-side project details:
With regards to my client-side react project, installing web3 as a dependency and webpacking results in the following error:
Module not found: Error: Can't resolve 'websocket' in '/home/circleci/project/node_modules/web3-providers-ws/src'
. This is what the package.json dependencies looks like for that project:This error magically goes away if I remove web3 from my
package.json
dependencies, and manually run:npm install [email protected] --save --save-exact --unsafe-perm=true
before webpacking my client-side bundle. This means I exclude web3 from my package.json dependencies, and run an extra step afterwards to install web3. I really don't like this, as it prevents me from generating a comprehensive package-lock.json.It seems like one of the web3 dependencies needs more expansive file permissions in order to compile. Interestingly, this does not happen when I bundle via webpack locally on MacOS, only in my linux OS ci pipeline. I did some research trying to figure out if NPM would let me specify the
--unsafe-perm
flag in my package.json file, but it appears that flag is only respected when installing a single package.Is there any solution for this, or am I stuck with an extra step installing web3 manually with
--unsafe-perm
?The text was updated successfully, but these errors were encountered: