Skip to content
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

Can't install web3 version 1.2 on Windows 10 #2971

Closed
taducquang opened this issue Jul 24, 2019 · 33 comments
Closed

Can't install web3 version 1.2 on Windows 10 #2971

taducquang opened this issue Jul 24, 2019 · 33 comments
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@taducquang
Copy link

taducquang commented Jul 24, 2019

Hi, i don't know why but seem like i can't install web3's latest version even on new project on Windows 10.
Command:
npm install web3 or yarn add web3

Details of Error:

rm -rf node_modules/websocket/.git

'rm' is not recognized as an internal or external command,
operable program or batch file.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web3-providers-ws@1.2.0 preinstall: `rm -rf node_modules/websocket/.git`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web3-providers-ws@1.2.0 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Versions

  • web3.js: 1.2
  • nodejs: 10.16.0
  • OS: Windows 10
@lihenan1993
Copy link

I have encountered the same problem

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! web3-providers-ws@1.2.0 preinstall: rm -rf node_modules/websocket/.git npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the web3-providers-ws@1.2.0 preinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Versions

  • web3.js: 1.2
  • nodejs: 10.16.0
  • OS: Windows 10

@filips123
Copy link
Contributor

This is because package web3-providers-ws uses pre-install script which contains rm command to delete websocket's .git directory. But rm command is not availible on Windows.

@levino
Copy link
Contributor

levino commented Jul 25, 2019

To clarify what @filips123 said: This is a bug in web3 and currently makes 1.2.x incompatible with Windows. Needs to be fixed.

@filips123
Copy link
Contributor

@levino Why does package need to delete .git directory? If it is really needed, it needs to be fixed to use rm -r or rmdir depending on what's available.

@levino
Copy link
Contributor

levino commented Jul 25, 2019

I was not talking about a fix. I was talking about the status quo: You cannot install this package on Windows atm. I do not know why there is a preinstall script and I have not looked into how this can be fixed. Your analysis above sounds right. I just wanted to clarify that this is a bug that needs to be fixed here. One could read your comment like instructions for a workaround, which they are not.

@nivida nivida added 1.x 1.0 related issues Bug Addressing a bug labels Jul 25, 2019
@michaelsbradleyjr
Copy link
Contributor

michaelsbradleyjr commented Jul 25, 2019

The preinstall script is a red herring, and isn't needed; it should be removed from web3-providers-ws because it's pointless. rm works fine on Windows, not sure exactly what's gone wrong in this case, but I think it's a permissions problem.

There's a nasty bug in npm that's fixed in 6.10.1: https://npm.community/t/installing-with-git-url-results-in-spurious-git-directory-within-node-modules/8815.

(this after-effects of this bug can manifest weird behavior on Windows like not being able to delete sudirs in node_modules, no idea why though)

To overcome this problem, you may need to do a combination of the following, or all of them:

  • upgrade to npm 6.10.1 or newer
  • clear your npm cache: npm cache clear --force
  • delete your project's node_modules directory
  • manually edit your project's package-lock.json or as a last resort delete it and regenerate it.

@michaelsbradleyjr
Copy link
Contributor

michaelsbradleyjr commented Jul 26, 2019

On Windows I found I had to upgrade to the latest npm (6.10.2) and/or I had to run npm cache clear --force in an admin shell... I'm not sure which of those things did the trick, maybe both together. But it's definitely an npm thing, not a problem with web3 per se.

@taducquang
Copy link
Author

Not really an idea solution if i have to upgrade npm since it comes with nodejs LTS version.
How about Yarn @michaelsbradleyjr?

@devedse
Copy link

devedse commented Jul 26, 2019

  • I installed the latest version of Node-Gyph because apparently the current version is not compatible with Node 12.x: Fails to install with node 12 microsoft/node-pty#319
  • I did an upgrade of npm by doing this: npm install -g npm
  • After that I cleaned the npm cache: npm cache clear --force
  • I removed the node_modules and package-lock.json
  • Restarted my terminal and executed npm install.

I still run into the same error though:
image

@michaelsbradleyjr
Copy link
Contributor

michaelsbradleyjr commented Jul 26, 2019

@devedse the screenshot helped me understand, thank you! @taducquang I apologize for a bit of misdirection in my previous replies. Indeed, rm isn't available in cmd.exe by default.

I've kept a Windows laptop (or at least a VM) around for cross-platform testing the past couple of years, but one of the first things I do when setting up a Windows environment is install tools like cmder and Git for Windows (note: there is a cmder download that bundles the two things). That makes *nix commands like rm available in the shell (note it's not a bash shell, it's an augmented cmd.exe environment that cmder provides).

image

So the "fix" in this case will be to remove the preinstall script from web3-providers-ws. I'll make a PR shortly. An alternative fix, if the preinstall script was actually needed, would be to make rimraf a dependency of web3-providers-ws and have the script use the rimraf command instead of rm.

As for the npm bug I linked to earlier — it's a real thing over which web3 has no control and there's no easy way to get around it other than for users to upgrade their npm, sorry @taducquang. Maybe web3 1.x can switch to using a websocket version that's downloaded from the registry (change already made in web3 2.x), but I think there's still some problem whereby web3 1.x needs to install the version directly from github — it's the install from github that triggers the bug. Note that on linux/macOS using a github: specifier instead of git:// masks the bug (for reasons I don't know) but on Windows the bug shows up either way and the only fix I found is to use latest npm.

@sabby19
Copy link

sabby19 commented Jul 27, 2019

Can any one please help? can't install web3 on windows
image

@michaelsbradleyjr
Copy link
Contributor

michaelsbradleyjr commented Jul 27, 2019

@sabby19 after discussing with @nivida the plan is to switch from the github: specifier that installs the websocket package from a fork on github to a version that will come from the NPM registry. The preinstall script that's causing problems on Windows will also be removed. Both changes will likely land together in a forthcoming release of web3 1.x.

In the meantime, you can install the Cmder bundle that includes Git for Windows. Also, you will need to upgrade to the latest npm (6.10.2 presently). When running npm install commands in a Cmder (+ Git for Windows) session the rm command should be available. And the upgraded npm will prevent your being affected by the npm bug re: dependencies installed from github:/git:// specifiers.

@devedse
Copy link

devedse commented Jul 28, 2019

@michaelsbradleyjr, as part of integration testing / builds / etc. it might be a good idea to setup a TravisCI build to do a clean NPM install (from source) for Web3.js and the same for AppVeyor. That will help catch issues like this in an early stage.

@levino
Copy link
Contributor

levino commented Jul 28, 2019

Yeah. Or one might start having some integration tests first...

@devedse
Copy link

devedse commented Jul 28, 2019

Oh

michaelsbradleyjr added a commit to michaelsbradleyjr/web3.js that referenced this issue Jul 28, 2019
The `michaelsbradleyjr/Websocket-Node#polyfill/globalThis` branch uses a more
robust approach to resolve a browser's `window` object. It also includes all
the latest commits on the upstream's `master` branch, including fixes for the
`.git/` subdir npm bug and Node v12.x compatibility.

The `"preinstall"` script in `packages/web3-providers-ws/package.json` is
removed because it's not helpful and its use of `rm` causes Windows
incompatibility. Closes web3#2971 and web3#2973.

`packages/web3-providers-ws/src/index.js` is refactored since the `websocket`
package already does native WebSocket detection.
michaelsbradleyjr added a commit to michaelsbradleyjr/web3.js that referenced this issue Jul 29, 2019
The `michaelsbradleyjr/Websocket-Node#polyfill/globalThis` branch uses a more
robust approach to resolve a browser's `window` object. It also includes all
the latest commits on the upstream's `master` branch, including Node v12.x
compatibility and a workaround for the `.git/` subdir npm bug.

The `"preinstall"` script in `packages/web3-providers-ws/package.json` is
removed because it's not helpful and its use of `rm` causes Windows
incompatibility. Closes web3#2971 and web3#2973.

`packages/web3-providers-ws/src/index.js` is refactored since the `websocket`
package already does native WebSocket detection.
@nivida
Copy link
Contributor

nivida commented Jul 31, 2019

Fixed with #2976

@nivida nivida closed this as completed Jul 31, 2019
@devedse
Copy link

devedse commented Jul 31, 2019

@nivida, can I retest this issue already using some kind of beta NPM source? Or do I have to wait for the next release?

@filips123
Copy link
Contributor

@nivida When it will be released?

@levino
Copy link
Contributor

levino commented Jul 31, 2019

Possibly there should be a release day like every monday or so where there is a release of latest master if changes were merged.

@devedse
Copy link

devedse commented Jul 31, 2019

@levino, I'd rather have nightly builds with a beta release path and let the package maintainers decide on when to release master to production. Else you could end up with 'semi broken' or 'not finished' versions of the package getting released to NPM.

@filips123
Copy link
Contributor

@devedse I agree with that. But there is no need to create nightly releases. Users who want to try the latest unreleased changes can just require Web3 directly from GitHub:

{
  "dependencies": {
    "web3": "github:ethereum/web3.js#1.x"
  }
}

@levino
Copy link
Contributor

levino commented Jul 31, 2019

No you cant. This is a lerna monorepo. How on earth could that work?

@filips123
Copy link
Contributor

@levino I forgot that... Maybe lerna has some features for that?

@levino
Copy link
Contributor

levino commented Jul 31, 2019

No it does not. One has to publish the package to npm. There is no workaround. I for my part just publish it to @levino/web3.js which is a nightmare because I have to update and publish all subpackages too.

@levino
Copy link
Contributor

levino commented Jul 31, 2019

@levino, I'd rather have nightly builds with a beta release path and let the package maintainers decide on when to release master to production. Else you could end up with 'semi broken' or 'not finished' versions of the package getting released to NPM.

Sorry, but that approach is very wrong. master should never have any state that "package maintainers cannot publish". Basically the processes need to be improved and then you can "autopublish on merge to master".

@devedse
Copy link

devedse commented Jul 31, 2019

@levino, if you can make sure that every change being merged to master has been fully tested and is ready for production I'd agree. From my experience most master branches are used for 'Beta' versions as well. Once the beta version is stabilized, a release will be made.

Take for example the change that was just merged to master. I'm sure this has been tested on local environments but as there are no integration tests nor has it been tested by the mass I wouldn't specifically call this to be "Fully tested".

It's up to the maintainers to make a choice in this of course, and I agree that it would be ideal to autopublish on merge to master. But in my oppinion that publish should only ever be a beta release rather then a full fledged new version.

(E.g. think about the way Microsoft handles different versions of releasing windows. You can choose between different insider tracks depending on whether you want the latest "Master" build or rather have the more tested "Release")

Edit: This discussion is probably going too far off-topic anyway :). Let's hope we can release the new version of web3.js asap.

@levino
Copy link
Contributor

levino commented Jul 31, 2019

Or one just releases it and sees who has a problem. People use package-lock.json these days so not everyone is going to update immediatly. People will start screaming slowly. They can fix it by going back one version until the currently broken version is fixed. I mean: When there are some buggy changes on master in this repo, do you really think these bugs will be found by anyone before they are published? Nobody is testing this at all.

@devedse
Copy link

devedse commented Jul 31, 2019

@levino, I think we both agree on the problem. Nobody is testing their stuff before it's published. Regarding the best practical solution I agree that simply releasing it and hoping that issues get found quickly is probably one of the more easy solutions to implement.

Let's leave it at that 😄

@KimJuHeok
Copy link

You guys can use git bash for install web3@1.2

@levino
Copy link
Contributor

levino commented Aug 2, 2019

Please elaborate

@KimJuHeok
Copy link

KimJuHeok commented Aug 2, 2019

Please elaborate
Just install git bash and type npm install --save web3.
Git bash can execute "rm" command that causes problem.
And also It did work perfectly.

@fabio-s-franco
Copy link

Git Bash solved the issue for me in Windows

@DavidWang96
Copy link

Do it with Git Bash

nachomazzara pushed a commit to nachomazzara/web3.js that referenced this issue Jun 4, 2020
The `michaelsbradleyjr/Websocket-Node#polyfill/globalThis` branch uses a more
robust approach to resolve a browser's `window` object. It also includes all
the latest commits on the upstream's `master` branch, including Node v12.x
compatibility and a workaround for the `.git/` subdir npm bug.

The `"preinstall"` script in `packages/web3-providers-ws/package.json` is
removed because it's not helpful and its use of `rm` causes Windows
incompatibility. Closes web3#2971 and web3#2973.

`packages/web3-providers-ws/src/index.js` is refactored since the `websocket`
package already does native WebSocket detection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests