question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm dependencies issue with pre-commit 2.8.1 ?

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sbidoulcommented, Oct 30, 2020

@asottile Thanks for the analysis and detailed explanation.

0reactions
asottilecommented, Oct 30, 2020

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 broken

fortunately, and they’re in the progress of migrating this anyway, the prettier/pre-commit repository doesn’t have this limitation

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0501dd9..18f645f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,12 +1,13 @@
 default_language_version:
   node: "14.15.0"
 repos:
-  - repo: https://github.com/prettier/prettier
-    rev: 2.1.2
+  - repo: https://github.com/prettier/pre-commit
+    rev: v2.1.2
     hooks:
       - id: prettier
         name: prettier + plugin-xml
         additional_dependencies:
+          - "prettier@2.1.2"
           - "@prettier/plugin-xml@0.12.0"
         args:
           - --plugin=@prettier/plugin-xml

so tl;dr is switch to prettier/pre-commit as their repository isn’t correctly git installable

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found