npm ci
doesn't run the postinstall
script
npm ci
should run the postinstall
script
{
"scripts": {
"postinstall": "echo \"it should echo this\""
}
}
npm install
npm ci
npm ci
DOES NOT run the postinstall
scriptex.
I think this is functioning as intended or at least the same as npm v6
& doesn't look like a bug but probably is very confusing.
The preinstall
, install
& postinstall
scripts are actually lifecycle events that are triggered when a package itself is being installed into another project or as a dependency. That said, you can trigger these scripts manually using npm run
.
If you want to execute some code every time you run install
at the project level, I think you'll want to use hook scripts
(ie. define an executable with the same name as the event in ./node_modules/.hooks/
).
Definitely let me know if I'm wrong though & that this is/was working on a previous version of the CLI. Other option here is just to chain (ie. npm install x && npm run y
, or we've got handy commands like install-test
& install-ci-test
which do an npm install
then npm run test
which is/was a common workflow for folks)
This is not how npm 6 works.
npm 6:
npm 7:
Hmm, looking into this a bit more, I know that we did want to quiet down installs & we did implement an RFC for that (ref. https://github.com/npm/rfcs/blob/latest/implemented/0022-quieter-install-scripts.md); But we should still be running those. I'll file this & see if we can get someone to dig in a bit more.
I can second this. I have projects using Husky. When doing a fresh install, Husky does not run, nor does it install the git hooks. This was changed from NPM v6 to NPM v7. One thing that's slightly different than OP's issue, is that (I believe) the postinstall scripts run are in Husky's module, and not in the root project's scripts.
Example npm ci
snippet for Husky:
$ npm ci
npm WARN prepare removing existing node_modules/ before installation
> [email protected] install ./atlas-server/node_modules/husky
> node husky install
husky > Setting up git hooks
husky > Done
> [email protected] postinstall ./atlas-server/node_modules/husky
> opencollective-postinstall || exit 0
Thank you for using husky!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/husky/donate
...
I'm using lerna
and using postinstall
on my project like below.
"scripts": {
"postinstall": "lerna bootstrap",
https://github.com/mobilusoss/textlint-browser-runner/blob/master/package.json#L18
postinstall
was called after npm ci
on TravisCI with npm v 6.14.8
https://travis-ci.com/github/mobilusoss/textlint-browser-runner/builds/191070080
But npm v7.0.3 does not call postinstall
https://travis-ci.com/github/mobilusoss/textlint-browser-runner/jobs/403527216
My solution is calling lerna bootstrap
manually after npm ci
Confirm. Breaking change since npm 7.0.0
Probably caused by
Commands that just run a single script (npm test, npm start, npm stop, and npm restart) will now run their script even if --ignore-scripts is set. Prior to the GA v7.0.0 release, they will not run the pre/post scripts, however. (So, it'll be possible to run npm test --ignore-scripts to run your test but not your linter, for example.)
Will this be considered as a bug or as a breaking change for npm 7?
@darcyclarke @isaacs apologies for the direct tags, but I see that this issue was removed from one of the sprint milestones, so I want to make sure that it wasn't overlooked as it's a fairly major regression.
Here's a minimal repro, in case it's not clear from the original issue:
{
"scripts": {
"prepare": "echo foo"
}
}
With npm@6
, both npm install
and npm ci
print "foo". With npm@7
, npm install
prints "foo" but npm ci
does not.
The problem is that the install command has the following block to explicitly run the appropriate install scripts, but the ci command has no such block:
https://github.com/npm/cli/blob/a28aff769a77f127f371c31afcb9e9814722e5cd/lib/install.js#L44-L62
Most helpful comment
@darcyclarke @isaacs apologies for the direct tags, but I see that this issue was removed from one of the sprint milestones, so I want to make sure that it wasn't overlooked as it's a fairly major regression.
Here's a minimal repro, in case it's not clear from the original issue:
With
npm@6
, bothnpm install
andnpm ci
print "foo". Withnpm@7
,npm install
prints "foo" butnpm ci
does not.The problem is that the install command has the following block to explicitly run the appropriate install scripts, but the ci command has no such block:
https://github.com/npm/cli/blob/a28aff769a77f127f371c31afcb9e9814722e5cd/lib/install.js#L44-L62