SimenB / add-asset-html-webpack-plugin

Add a JavaScript or CSS asset to the HTML generated by html-webpack-plugin
MIT License
335 stars 42 forks source link

Issue with husky install in post install script #373

Open cole-adams opened 1 year ago

cole-adams commented 1 year ago

I'm attempting to upgrade to the latest version of this package, and I'm getting the following error:

npm ERR! code 127
npm ERR! path <project>/node_modules/add-asset-html-webpack-plugin
npm ERR! command failed
npm ERR! command sh -c husky install
npm ERR! sh: husky: command not found

We don't use husky in our project. I notice the post install script for this package is husky install which I believe is no longer best practice for husky.

Is there any way to resolve this?

louishust commented 10 months ago

I encounter almost the same problem.

7692 timing command:install Completed in 40492ms
7693 verbose stack Error: command failed
7693 verbose stack     at ChildProcess.<anonymous> (/Users/loushuai/workspace/testing/metersphere/.node/node/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27)
7693 verbose stack     at ChildProcess.emit (node:events:514:28)
7693 verbose stack     at maybeClose (node:internal/child_process:1105:16)
7693 verbose stack     at Socket.<anonymous> (node:internal/child_process:457:11)
7693 verbose stack     at Socket.emit (node:events:514:28)
7693 verbose stack     at Pipe.<anonymous> (node:net:337:12)
7694 verbose pkgid add-asset-html-webpack-plugin@6.0.0
7695 verbose cwd /Users/loushuai/workspace/testing/metersphere/api-test/frontend
7696 verbose Darwin 23.0.0
7697 verbose node v20.8.1
7698 verbose npm  v10.1.0
7699 error code 1
7700 error path /Users/loushuai/workspace/testing/metersphere/api-test/frontend/node_modules/add-asset-html-webpack-plugin
7701 error command failed
7702 error command sh -c husky install
7703 error husky - .git can't be found (see https://typicode.github.io/husky/#/?id=custom-directory)
7704 verbose exit 1

then when executing npm install , i run git init in the node_modules/add-asset-html-webpack-plugin directory, then npm install success.

Then i remove the whole node_modules directory, and try again, it's supposed to be failed again, but amazing, it success, and i do not known why

gerhat commented 10 months ago

Same issue here. I had to downgrade to 3.2.2.

cha0s commented 7 months ago

Still happening! Can't even use patch-package. I tried.

This package is completely broken!

cha0s commented 7 months ago

For anyone totally lost, the only way to make this package work is to do e.g.

npm install --save-dev husky

in your project. Fortunately, it's a pretty small package!

SimenB commented 2 months ago

Hmm, this shouldn't be an issue as I've got pinst setup. And I can see in the published artifact that postinstall is renamed correctly to _postinstall so that it shouldn't run.

https://www.runpkg.com/?add-asset-html-webpack-plugin@6.0.0/package.json#20

What version are you attempting to install?

cha0s commented 2 months ago

Sorry, I'm not using webpack anymore. I'm not sure what the issue is/was.

zburke commented 1 month ago

In a package with a transitive dependency on ^6.0.0, installation via npm i fails with the following in the error log:

[...]
12243 10583 verbose stack Error: command failed
12244 10583 verbose stack     at promiseSpawn (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:22:22)
12245 10583 verbose stack     at spawnWithShell (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:124:10)
12246 10583 verbose stack     at promiseSpawn (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:12:12)
12247 10583 verbose stack     at runScriptPkg (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:77:13)
12248 10583 verbose stack     at runScript (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script.js:9:12)
12249 10583 verbose stack     at /Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/rebuild.js:329:17
12250 10583 verbose stack     at run (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/promise-call-limit/dist/commonjs/index.js:67:22)
12251 10583 verbose stack     at /Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/promise-call-limit/dist/commonjs/index.js:84:9
12252 10583 verbose stack     at new Promise (<anonymous>)
12253 10583 verbose stack     at callLimit (/Users/zburke/.nvm/versions/node/v20.11.1/lib/node_modules/npm/node_modules/promise-call-limit/dist/commonjs/index.js:35:69)
12254 10584 verbose pkgid add-asset-html-webpack-plugin@6.0.0
12255 10585 error code 127
12256 10586 error path /Users/zburke/temp/stripes-core/node_modules/add-asset-html-webpack-plugin
12257 10587 error command failed
12258 10588 error command sh -c husky install
12259 10589 error sh: husky: command not found

This package installs cleanly without errors with yarn v1 or with npm i --ignore-scripts. Environment details:

$ uname -a
Darwin LP-C02G8208ML85 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:09:52 PDT 2024; root:xnu-10063.121.3~5/RELEASE_X86_64 x86_64
$ node -v
v20.11.1
$ npm -v 
10.8.2
SimenB commented 1 month ago

mkdir test && cd test && npm init -y && npm install --save-dev add-asset-html-webpack-plugin works fine... Do you have a reproduction?

zburke commented 1 month ago

@SimenB : Here are reproduction steps:

git clone git@github.com:folio-org/stripes-core.git
cd stripes-core
echo "@folio:registry = https://repository.folio.org/repository/npm-folioci/" >> .npmrc
npm install

add-asset-html-webpack-plugin comes into this package, @folio/stripes-core, transitively through @folio/stripes-cli and @folio/stripes-webpack. I don't think we're doing anything interesting in stripes-webpack; it's just a regular ol' dep in package.json. Our current build pipeline uses yarn v1 but we're trying to migrate back to npm.

zburke commented 1 month ago

Related issues:

This is strange. It does feel like a bug in NPM >= 10.4.0, but as noted in the npm issue, then its impact should be bigger.