Skip to content

Pin node version #11

Description

@sterliakov

Node 23.0.0 was released 2 days ago and broke hooks in this repository. The log I receive is the following:

An unexpected error has occurred: CalledProcessError: command: ('/home/stas/.cache/pre-commit/repo6fs1kess/node_env-default/bin/node', '/home/stas/.cache/pre-commit/repo6fs1kess/node_env-default/bin/npm', 'pack')
return code: 254
stdout: (none)
stderr:
    (node:2233787) 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:/home/stas/.cache/pre-commit/repo6fs1kess/ (null) seems to be corrupted. Trying again.
    npm warn tarball tarball data for file:/home/stas/.cache/pre-commit/repo6fs1kess/ (null) seems to be corrupted. Trying again.
    npm error code ENOENT
    npm error syscall lstat
    npm error path /home/stas/.cache/pre-commit/repo6fs1kess/ode_env-default/lib/node_modules/npm/node_modules/sprintf-js/dist/.gitattributes
    npm error errno -2
    npm error enoent ENOENT: no such file or directory, lstat '/home/stas/.cache/pre-commit/repo6fs1kess/ode_env-default/lib/node_modules/npm/node_modules/sprintf-js/dist/.gitattributes'
    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: /home/stas/.npm/_logs/2024-10-18T16_37_40_681Z-debug-0.log
Check the log at /home/stas/.cache/pre-commit/pre-commit.log

NPM log is no more helpful. This is something related to node v23, and pre-commit defaults to using latest version. The problem is that npm pack works, while node npm pack for some reason does not, and pre-commit invokes the latter.

To reproduce (if this doesn't fail, try pre-commit clean prior to running this):

cd $(mktemp -d)
git init
cat >.pre-commit-config.yaml <<EOF
repos:
-   repo: https://github.com/biomejs/pre-commit
    rev: "v0.5.0"
    hooks:
    -   id: biome-check
        additional_dependencies: ["@biomejs/biome"]
EOF
pre-commit install
pre-commit install-hooks

Works:

cd $(mktemp -d)
git init
cat >.pre-commit-config.yaml <<EOF
repos:
-   repo: https://github.com/biomejs/pre-commit
    rev: "v0.5.0"
    hooks:
    -   id: biome-check
        additional_dependencies: ["@biomejs/biome"]
        language_version: '22.0.0'
EOF
pre-commit install
pre-commit install-hooks

language_version can be overridden by end users, but it's expected that hooks work "out of the box", hence pinning language_version here would be very helpful. (to make it clear, this does not depend on system node installation, so won't be exposed to users directly in any way)

Activity

  1. sterliakov commented on Oct 18, 2024

    @sterliakov
    ContributorAuthor

    Here's an upstream confirmation: already discovered in pre-commit/pre-commit#3339 and caused by nodejs/node#55410. Also good suggestion from that thread to use language_version: lts to avoid pinning to any specific release.

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