igorshubovych / markdownlint-cli

MarkdownLint Command Line Interface
MIT License
849 stars 86 forks source link

Installation error in pre-commit with node version >22 #506

Open dischii opened 1 day ago

dischii commented 1 day ago

Installation error in pre-commit with node version >22

Summary

The installation markdownlint-cli in my pre-commit configuration does not work with the current version of node: v23.10.0.
In my Windows Environment in VSCode i can't execute the pre-commit with this package.

Error Message

[INFO] Installing environment for https://github.com/igorshubovych/markdownlint-cli.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('C:\\Users\\xxx\\.cache\\pre-commit\\repomtnety1c\\node_env-default\\Scripts\\npm.CMD', 'install', '--include=dev', '--include=prod', '--ignore-prepublish', '--no-progress', '--no-s
'--no-save')
return code: 1
stdout: (none)
stderr:
    (node:29492) ExperimentalWarning: CommonJS module C:\Users\xxx\.cache\pre-commit\repomtnety1c\node_env-default\Scripts\node_modules\npm\node_modules\debug\src\node.js is loading ES Module C:\Users\xxx\.cache\pre-commit\repomtnety1c\node1c\node_env-default\Scripts\node_modules\npm\node_modules\supports-color\index.js using require().
    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 error code EBADENGINE
    npm error engine Unsupported engine
    npm error engine Not compatible with your version of node/npm: ava@6.1.3
    npm error notsup Not compatible with your version of node/npm: ava@6.1.3
    npm error notsup Required: {"node":"^18.18 || ^20.8 || ^21 || ^22"}
    npm error notsup Actual:   {"npm":"10.9.0","node":"v23.1.0"}
    npm error A complete log of this run can be found in: C:\Users\xxx\AppData\Local\npm-cache\_logs\2024-10-30T13_45_40_988Z-debug-0.log
Check the log at C:\Users\xxx\.cache\pre-commit\pre-commit.log

Possible but failed solution

Unfortunately, I didn't found any solution how to configure pre-commit to use an earlier node version.
I tried already the use of nvm but pre-commit use still the latest version v23.1.0:

nvm install 22.10.0
nvm use 22.10.0

Acceptance Criteria

  1. One solution is to support the newest version of node (v23.1.0) with this package
  2. Possible Workaround how to use different environments for local configuration of pre-commit (note: it wouldn't be a good solution for me to select the static version in the pre-commit-config.yaml file because it should be used from other participants and in my linux environment it is working sufficient)
DavidAnson commented 1 day ago

The underlying issue is a known problem the pre-commit team does not want tools like this to fix. You can read more in this issue (which links back to this repo eventually): https://github.com/DavidAnson/markdownlint-cli2/issues/437

Your error message is different than the one I linked above (and present in a more recent duplicate of it), but fundamentally you want the tool to declare supported versions of Node and the pre-commit team forbid that.

So far as I know, what you suggest in option two at the bottom is the appropriate path forward. Or you might consider one of the proposals from the creator of the issue I link above.

Sorry about the trouble, I wish I understood why it has to be this way.

DavidAnson commented 1 day ago

Looking at this again, I do not see anything in the error messages above that points to this project being the cause. (Maybe the full log file has more to go on?)

The best I can guess is the version of ava being used declares itself unable to run on Node 23 and pre-commit is unwilling to use Node 22 instead. But this is irrelevant because ava is a devDependency and therefore not needed at runtime anyway.