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! [email protected] preinstall: `rm -rf node_modules/websocket/.git`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I have encountered the same problem
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] preinstall:rm -rf node_modules/websocket/.git
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Versions
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.
To clarify what @filips123 said: This is a bug in web3 and currently makes 1.2.x incompatible with Windows. Needs to be fixed.
@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.
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.
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:
npm cache clear --forcenode_modules directorypackage-lock.json or as a last resort delete it and regenerate it.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.
Not really an idea solution if i have to upgrade npm since it comes with nodejs LTS version.
How about Yarn @michaelsbradleyjr?
npm install -g npmnpm cache clear --forcenpm install.I still run into the same error though:

@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).

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.
Can any one please help? can't install web3 on windows

@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.
@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.
Yeah. Or one might start having some integration tests first...
Oh
Fixed with #2976
@nivida, can I retest this issue already using some kind of beta NPM source? Or do I have to wait for the next release?
@nivida When it will be released?
Possibly there should be a release day like every monday or so where there is a release of latest master if changes were merged.
@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.
@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"
}
}
No you cant. This is a lerna monorepo. How on earth could that work?
@Levino I forgot that... Maybe lerna has some features for that?
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, 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".
@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.
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.
@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 😄
You guys can use git bash for install [email protected]
Please elaborate
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.
Git Bash solved the issue for me in Windows
Do it with Git Bash
Most helpful comment
Yeah. Or one might start having some integration tests first...