Skip to content

npm tries to access incorrect path ib/ instead of lib/ #3339

Description

@kolvin

search you tried in the issue tracker

Searched for issues related to npm path errors, missing files in hooks, path mismatches.

describe your issue

Scratching my head on this one; this error appeared as soon as I ran my first commit this morning. As far as I can see, no versions had changed to trigger the error.

When running pre-commit, npm tries to access a file in the path ib/file.js instead of lib/file.js, causing an ENOENT error because the file is actually in lib/ and not ib/.

I expected npm to find the file correctly, but it results in a path error.

I've tried uninstalled and reinstalled pre-commit using both Homebrew and pip across different versions, but the error persists with no change. I’ve also tested this with a few different Node versions 18 and 22.6.0, and the issue remains unchanged.

The issue occurs both on my local machine and in a Docker environment, which helps rule out any variables related to my local environment.

I checked the path of the "missing file" and found the real location:

tree /Users/kolvin/.cache/pre-commit/repoqmt76wwe/lib/
/Users/kolvin/.cache/pre-commit/repoqmt76wwe/lib/
├── file.js
├── get-html-headers.js
└── transform.js

Error:

npm error enoent ENOENT: no such file or directory, lstat '/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ib/get-html-headers.js'
npm error enoent This is related to npm not being able to find a file.

A test:

ln -s lib ib

Result:

pre-commit run --all-files

[INFO] Installing environment for https://github.com/thlorenz/doctoc.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Check for useless excludes...............................................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check that executables have shebangs.................(no files to check)Skipped
check json...........................................(no files to check)Skipped
check for merge conflicts................................................Passed
fix end of files.........................................................Passed
doctoc...................................................................Failed
- hook id: doctoc
- exit code: 1

node:internal/modules/cjs/loader:1262
  throw err;
  ^

Error: Cannot find module './lib/file'
Require stack:
- /Users/kolvin/.cache/pre-commit/repoqmt76wwe/node_env-default/lib/node_modules/doctoc/doctoc.js

pre-commit --version

pre-commit 3.7.1 (also tested with 4.0.1)

.pre-commit-config.yaml

repos:
  - repo: meta
    hooks:
      - id: check-useless-excludes
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: check-added-large-files
        args: ["--maxkb=700"]
      - id: check-case-conflict
      - id: check-executables-have-shebangs
      - id: check-json
      - id: check-merge-conflict
      - id: end-of-file-fixer
  - repo: https://github.com/thlorenz/doctoc
    rev: v2.2.0
    hooks:
      - id: doctoc
        args: ["--title=## Contents", "--gitlab"]
        description: "Generates table of contents for markdown files"

~/.cache/pre-commit/pre-commit.log (if present)

version information

pre-commit version: 3.7.1
git --version: git version 2.43.2
sys.version:
    3.11.10 (main, Sep  7 2024, 01:03:31) [Clang 15.0.0 (clang-1500.3.9.4)]
sys.executable: /opt/homebrew/opt/[email protected]/bin/python3.11
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/Users/kolvin/.cache/pre-commit/repoqmt76wwe/node_env-default/bin/node', '/Users/kolvin/.cache/pre-commit/repoqmt76wwe/node_env-default/bin/npm', 'pack')
return code: 254
stdout: (none)
stderr:
    (node:24867) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    npm warn tarball tarball data for file:/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ (null) seems to be corrupted. Trying again.
    npm warn tarball tarball data for file:/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ (null) seems to be corrupted. Trying again.
    npm error code ENOENT
    npm error syscall lstat
    npm error path /Users/kolvin/.cache/pre-commit/repoqmt76wwe/ib/get-html-headers.js
    npm error errno -2
    npm error enoent ENOENT: no such file or directory, lstat '/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ib/get-html-headers.js'
    npm error enoent This is related to npm not being able to find a file.
    npm error enoent
    npm error A complete log of this run can be found in: /Users/kolvin/.npm/_logs/2024-10-17T13_08_26_638Z-debug-0.log
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/main.py", line 417, in main
    return run(args.config, store, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/commands/run.py", line 442, in run
    install_hook_envs(to_install, store)
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/repository.py", line 238, in install_hook_envs
    _hook_install(hook)
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/repository.py", line 94, in _hook_install
    lang.install_environment(
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/languages/node.py", line 101, in install_environment
    _, pkg, _ = cmd_output('npm', 'pack', cwd=prefix.prefix_dir)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/util.py", line 117, in cmd_output
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pre_commit/util.py", line 111, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/Users/kolvin/.cache/pre-commit/repoqmt76wwe/node_env-default/bin/node', '/Users/kolvin/.cache/pre-commit/repoqmt76wwe/node_env-default/bin/npm', 'pack')
return code: 254
stdout: (none)
stderr:
    (node:24867) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    npm warn tarball tarball data for file:/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ (null) seems to be corrupted. Trying again.
    npm warn tarball tarball data for file:/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ (null) seems to be corrupted. Trying again.
    npm error code ENOENT
    npm error syscall lstat
    npm error path /Users/kolvin/.cache/pre-commit/repoqmt76wwe/ib/get-html-headers.js
    npm error errno -2
    npm error enoent ENOENT: no such file or directory, lstat '/Users/kolvin/.cache/pre-commit/repoqmt76wwe/ib/get-html-headers.js'
    npm error enoent This is related to npm not being able to find a file.
    npm error enoent
    npm error A complete log of this run can be found in: /Users/kolvin/.npm/_logs/2024-10-17T13_08_26_638Z-debug-0.log

Activity

  1. asottile commented on Oct 17, 2024

    @asottile
    Member

    please report to nodeenv

  2. acolombier commented on Oct 17, 2024

    @acolombier
  3. kolvin commented on Oct 17, 2024

    @kolvin
    Author

    Hey @acolombier thanks for responding!

    Not sure I follow your patch though, where should that be run?

  4. asottile commented on Oct 17, 2024

    @asottile
    Member

    that patch is a terrible idea, just use language_version it's what it is designed for

  5. acolombier commented on Oct 17, 2024

    @acolombier

    Thanks for your help - really appreciate you are taking the time to help resolve the issue here.

    have it default to LTS or system

    Thoughts?

  6. kolvin commented on Oct 17, 2024

    @kolvin
    Author
    repos:
      - repo: https://github.com/thlorenz/doctoc
        rev: v2.2.0
        hooks:
          - id: doctoc
            language_version: 22.10.0
            args: ["--title=## Contents", "--gitlab"]

    Okay, language_version: 22.10.0 resolved the error

    This is an okay solution for the short-term

  7. acolombier commented on Oct 17, 2024

    @acolombier
  8. kolvin commented on Oct 17, 2024

    @kolvin
    Author

    language_version: lts works for me however its not a value listed in nodeenv --list

  9. jasonwashburn commented on Oct 17, 2024

    @jasonwashburn

    fyi, didn't see it mentioned here yet, but I chased this yesterday as well. It's a bug in the node 23 release. Tracking issue here: (nodejs/node#55410)

  10. kolvin commented on Oct 17, 2024

    @kolvin
    Author

    Nice @jasonwashburn, thanks for linking this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions