npm dependencies issue with pre-commit 2.8.1 ?
See original GitHub issueHi,
Since 2.8.1 one of our node-based pre-commit hook started to fail. With 2.7.1 it works fine.
To reproduce, create a git repo with an empty test.js
file and the following .pre-commit-config.yaml
:
default_language_version:
node: "14.15.0"
repos:
- repo: https://github.com/prettier/prettier
rev: 2.1.2
hooks:
- id: prettier
name: prettier + plugin-xml
additional_dependencies:
- "@prettier/plugin-xml@0.12.0"
args:
- --plugin=@prettier/plugin-xml
pre-commit run -a
then fails with Error: Cannot find module 'prettier/doc'
. Cleaning the pre-commit cache and running the same with pre-commit 2.7.1 works fine.
[INFO] Initializing environment for https://github.com/prettier/prettier.
[INFO] Initializing environment for https://github.com/prettier/prettier:@prettier/plugin-xml@0.12.0.
[INFO] Installing environment for https://github.com/prettier/prettier.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
prettier + plugin-xml....................................................Failed
- hook id: prettier
- exit code: 1
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'prettier/doc'
Require stack:
- /home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/@prettier/plugin-xml/src/embed.js
- /home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/@prettier/plugin-xml/src/plugin.js
- /home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/src/common/load-plugins.js
- /home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/src/index.js
- /home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/src/cli/index.js
- /home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/bin/prettier.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/@prettier/plugin-xml/src/embed.js:1:29)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/@prettier/plugin-xml/src/embed.js',
'/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/@prettier/plugin-xml/src/plugin.js',
'/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/src/common/load-plugins.js',
'/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/src/index.js',
'/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/src/cli/index.js',
'/home/me/.cache/pre-commit/repo_znxgdpn/node_env-14.15.0/lib/node_modules/prettier/bin/prettier.js'
]
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
simple-git-hooks
A simple, zero dependency tool for setting up git hooks for small projects. Latest version: 2.8.1, last published: 2 months ago.
Read more >simple-git-hooks - npm Package Health Analysis
A simple, zero dependency tool for setting up git hooks for small projects ... Ensure you're using the healthiest npm packages ... No...
Read more >pre-commit Changelog
- Fix `language: ruby` installs when `--user-install` is set in gemrc. - 2394 PR by narpfel. - 2393 issue by narpfel. - Adjust...
Read more >npm pre commit not working
Please, make sure that your 'package.json' file is in the same folder, where '.git' folder is (where git repository was initialized).
Read more >npm/CHANGELOG.md
115, dependency issue until the latter gets a dependency update. ... 1536, `package.json`, or even generate `CHANGELOG.md` automatically pre-commit if.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@asottile Thanks for the analysis and detailed explanation.
ok I’ve figured this out – it looks like this was only working by accident before 😦
prettier has prettier as a dev dependency and so the old way was installing all of the dev dependencies and pulling in prettier’s built distribution (unrelated to the actual version being installed!)
this is no longer happening and now the install is more like
npm install git+...
it turns out that prettier doesn’t install correctly via
npm install git+...
so their hook is just brokenfortunately, and they’re in the progress of migrating this anyway, the
prettier/pre-commit
repository doesn’t have this limitationso tl;dr is switch to prettier/pre-commit as their repository isn’t correctly
git
installable