Skip pre-commit hook in "npm version" command - javascript

npm version commits the change to package.json and creates a tag. Is there a way to prevent commit hook from being executed while using this command?

Not sure why this functionality didn't exist in npm before, but I contributed it a little while ago, as I needed it myself. It shipped with npm#5.4.0. To use it, set the config option commit-hooks = false in your .npmrc and the underlying git call will not run commit hooks when creating the version commit. If you only want to disable commit hooks on a single versioning, you can run something similar to:
npm version --no-commit-hooks minor
or alternatively:
npm version --commit-hooks false minor

According to npm cli docs you can skip the generation of a git tag by using
npm --no-git-tag-version version

From the docs
commit-hooks
Default: true
Type: Boolean
Run git commit hooks when using the npm version command.
If you simply want to allow this one time run the follow
npm version --no-commit-hooks patch|minor|major
To control this permanently, run the following command
npm config set commit-hooks false
Or add this line to your .npmrc file
commit-hooks=false

I tried all the above solutions, nothing worked for me.
the below command works well.
git commit -m "message" --no-verify

The following worked for me in a Git repo if you're looking for no tag and no commit but just the increment. (Replace patch with major or minor depending on your use case)
npm --no-git-tag-version version patch

Related

npm install: Verfication failed while extracting

READ BEFORE ANSWER: I've already solved this issue. It was a caching issue on the npm servers. Everything works fine after switching to GitHub packages. I've already accepted my own answer.
I have a project, which I want to deploy to elastic beanstalk but sometimes the deploy fails on the npm install script with the following message:
npm ERR! code EINTEGRITY
npm ERR! Verification failed while extracting #my-package#^1.2.0:
npm ERR! Verification failed while extracting #my-package#^1.2.0:
npm ERR! sha512-lQ...HA== integrity checksum failed when using sha512: wanted sha512-lQ...HA== but got sha512-nH...ow==. (4835509 bytes)
It fails even on packages which are severel weeks old.
I’ve tried:
npm cache clean --force
npm cache verify
node_modules is in .npmignore
package-lock.json is in .npmignore
Writing a mail to support#npmjs.com, but they replying always with some helpless default replies without any solution or intention to help.
It fails even on new elastic beanstalk instances.
I have no idea how to solve this problem.
EDIT: I've also tried to delete the npm cache while preinstall script, but it doesn't work either.
EDIT2: My repo has no package-lock.json.
EDIT3: My .npmrc file has the following content
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
unsafe-perm=true
package-lock=false
strict-ssl=false
EDIT4: I think it wasn't clear: It's a private package on the official npm registry. And it doesn't fail always. The current publish process includes several attempts to deploy on aws instance so long as it's succeed.
Have u try to delete package-lock.json?
OR
Try to delete npm and npm-cache folders
THEN
re-run npm install
Not exactly your case, but for those who run into the "integrity checksum failed" error the following might help. But first make sure you understand what's going on. npm tells you that the checksum from https://registry.npm.org doesn't match the one from package-lock.json. Either it changed in the registry, or...
Consider a line from the output:
npm ERR!
sha512-lQ...HA==
integrity checksum failed when using sha512: wanted
sha512-lQ...HA==
but got
sha512-nH...ow==
. (4835509 bytes)
Find the package in package-lock.json by the first two integrity checksums (sha512-lQ...HA==), and put the third one (sha512-nH...ow==) into its "integrity" field.
More on it here.
It seems to be a caching issue at the npm servers. We've switched from npm to GitHub packages, everything works fine there.
It could be that the version of NPM on these instances are out of date. Could you try either: npm install -g npm
Have you made sure that when this is deployed to beanstalk that the package-lock file is not on the instance? - If you have a bad lock file it needs to be deleted and re-generated.
Short of that, would need more information as you seem to have exhausted a lot of options.
This can happen if you request a version that is not available on the registry.
With #my-package#^1.2.0 you're requesting a version between >=1.2.0 and <2.0.0. Could it be that on this registry there is only a version that is older than 1.2.0 or newer than 2.0.0? Npm will install whatever it gets and not raise an error here.
You can check the version you get in an npm install by looking into node_modules/my-package/package.json.
If this is not happening when doing a local npm install, check wether the npm registry Amazon uses is containing your my-package package.
You could try to add the official npm registry to your Beanstalk project to check if it was the Amazon npm registry that did not contain your package. See How to use a private npm registry on Elastic Beanstalk? how to do this.
It seems to be a package-lock.json issue.
As in this answer
If you have not pushed package-lock.json in your repo, it will be generated while running npm install. So it is always better to add package-lock.json in the repo to avoid inconsistent package-lock.json files across local machine and deployment machine.
Could you please try pushing a fresh package-lock.json file to the repo and try?
In my case, as razki alludes to, the version of npm/node on the build server differed significantly from the version on the developer's local computer. Updating to a close enough version got rid of this problem.
For example:
The build server had: npm/6.13.4 node/v12.14.1
The developer has:    npm/6.14.8 node/v14.15.1.
The build server now: npm/6.14.10 node/v14.15.4
It seems the different versions calculate the sha differently for the same package. This is why removing the package-lock.json file can work in this particular situation - at least for a while, until the computer with the different version tries to build the project again.
Basically its concern about npm registery, Some home npm registery has been updated to another url.
You can run below command to see npm registery
npm config get registry
It should be set it
https://registry.npmjs.org/
If its not then run below command
npm config set registry https://registry.npmjs.org/
It will set npm registery. Now you can try again for
npm i
and it will install package successfully.

npx create-nuxt-app <project-name> not working

I want to create Nuxt.Js app using npx. But i am getting following error.
You have a space in your Windows username. This is a problem with NPX.
This is the path that NPM sees (which is right)
This is the path that NPX sees (which is wrong)
You can fix it by changing your NPM-Cache to another directory (without a space in the path):
npm config set cache C:\your\new\path\npm-cache --global
Source:
https://github.com/zkat/npx/issues/146#issuecomment-384016791
I changed npm-cache directory by writing following command
npm config set cache C:\tmp\nodejs\npm-cache --global
After that npx create-nuxt-app <project-name> worked perfectly.
I had it working using this command.
npm init nuxt-app <project-name>
This problem was resolved in a reddit
https://www.reddit.com/r/vuejs/comments/ie8vab/createnuxtapp_not_working_anyone_else_had_this/
Install it with:
npm i -g create-nuxt-app
Usually npm/npx should propose you to install, but it might not work
This issue can appear if during first try the installation was aborted
I have encountered similar problem and I have multiple spaces in the username.
If the above solutions does not work for you on Windows, there is another way.
Run VS code editor as an administrator.
Open the integrated terminal by clicking on Terminal > New Terminal or by pressing CTRL + SHIFT + '
Instead of using npx use the following
npm init nuxt-app project-name
Point number 3 will only work if you run the VS code editor as Administrator.
I am sure it is the same with external terminals. Run CMD/Gitbash as Administrator
Hope this helps. :D

GitKraken pre-commit fails but works in command line commit

I'm trying to commit any kind of change to a branch in my repository using GitKraken and get the following error every time:
whats strange is if I run git commit -m 'test' it commits without any errors. If I comment out the below line in my package.json then I can make commits in GitKraken no problem:
"precommit": "yarn check --integrity && lint-staged",
The person i've inherited the project from uses an Apple machine and he isn't experiencing any issues like this so not sure if that could be related. I'm also using node v8.9.4 and yarn v1.5.1
I've also tried deleting the yarn lock & node modules folder but still the same result. Anyone have an idea what might be going on here?
Check this issue, might be the answer, it has to do with the shell GitKraken uses by default in Windows:
https://github.com/typicode/husky/issues/243

Using specific version of npm shrinkwrap

I am deploying my node.js app to Appfog but since their install script cannot parse npm-shrinkwrap.json the whole deploy process fails.
An example dependency in shrinkwrap.json today looks like this
"async": {
"version": "0.2.10",
"from": "async#0.2.10", <--- This line breaks install script at appfog
"resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz"
},
I went through the whole shrinkwrap file and removed the "from" part from each dependency declaration and i managed to upload my application, and it works.
So my question is , how do i use an older version of npm shrinkwrap so i can get the version of shrinkwrap.json that i need?
Appfog support told me i need to use version 1.1.21 but i have not succeeded in installing it.
Please ask if some info is missing.
if you just want to use an older version of npm, you can install it via npm (i know that sounds strange, but its possible)
npm install npm#1.1.21
edit: so you try to install a version of npm which does not exist. just run
npm view npm
and take a look at the property version, to see which versions you could install via npm.
you will see that 1.1.21 does not exist in the registry, which means that you should try to install it via github (see answer by #sakai).
but then you see the next problem. you are using node#0.10.26, and npm 1.1.21 is probably not compatible with node#0.10.x.
so i for myself see basically 2 possible solutions:
Solution 1:
use n (or maybe nvm for switching node-versions back and forth. you could try to install a node#0.8.x version and try to install npm#1.1.21 there, and when done with shrinkwrapping switch back to your current node version.
Solution 2
you could setup some kind of grunt/gulp-task (i hope you use one of them) to run grunt/gulp shrinkwrap, which generates your shrinkwrap.json (via npm shrinkwrap) and when done cleans up your shrinkwrap.json
Try this:
npm install https://github.com/npm/npm/archive/v1.1.21.tar.gz
node ./node_modules/npm/bin/npm-cli.js shrinkwrap
Another—possibly simpler—solution is to just include node_modules into your repo.
Related: Should I check in node_modules to git when creating a node.js app on Heroku?

npm install forked git with submodule

I'm trying to get npm to install node-gitteh as a dependency via npm install which reads from package.json. Unfortunately this npm package is broken in node 0.6.x, but no problem as there's a forked repo that fixes the issues (https://github.com/hughsk/node-gitteh.git).
Now the issue is that this forked repo has a submodule, so if I try to download the tar from github in the package.json:
, "dependencies" : {
"gitteh" : "https://github.com/hughsk/node-gitteh/tarball/master"
}
I get an error that equates to "submodule folder not found". If I clone the same repo manually and do a recursive submodule update and an npm install from the node-gitteh folder, it works fine, but I can't figure out how to get npm to do this.
I've had the same problem and so far have just relied on cloning my module into node_modules and doing a submodule update manually. It would be nice to have npm handle this automatically.
In package.json there's a scripts field (see npm docs)
So could do
"scripts":{"preinstall": "git submodule update -i -r"}
See https://github.com/isaacs/octave-test for an example of this.
According to the docs, you need to supply the git url in a special format.
Also, it needs to point to git repo (same address you would use for git clone), not the tarball provided by github.
In your case (git over https), it would be:
, "dependencies" : {
"gitteh" : "git+https://github.com/hughsk/node-gitteh"
}
Using this, npm will default to the master branch.

Categories