theoludwig / markdownlint-rule-relative-links

Custom rule for markdownlint to validate relative links.
https://www.npmjs.com/package/markdownlint-rule-relative-links
MIT License
9 stars 1 forks source link

[Bug] package cannot be imported when installed with `npm install -g` #3

Closed zinizhu closed 8 months ago

zinizhu commented 11 months ago

I am trying to use markdownlint-cli2 as part of my CI GitHub workflow. To install this package it runs:

npm install -g markdownlint-rule-relative-links@2.1.0

However when I run the markdownlint-cli2 action it gives me

Run DavidAnson/markdownlint-cli2-action@ed4dec634fd2ef689c7061d5647371d8248064f1
  with:
    globs: markdown-test/index.md
    config: .markdownlint-cli2.jsonc
    separator: ,
markdownlint-cli2 v0.10.0 (markdownlint v0.31.1)
Error: Failed due to error: AggregateError: Unable to require or import module 'markdownlint-rule-relative-links'.

Steps To Reproduce

  1. Add the above command as a step in GitHub workflow
  2. Run the workflow

The current behavior

The markdownlint-cli cannot find the installed package.

The expected behavior

The action should run without error.

theoludwig commented 11 months ago

Hey! :wave: @zinizhu

Thanks for your bug report. I don't know exactly what could be the cause, but you should be able to run npm install --save-dev markdownlint-rule-relative-links@2.1.0 instead of npm install -g markdownlint-rule-relative-links@2.1.0 in your GitHub workflow, and it should work.

zinizhu commented 11 months ago

Thanks for the fast response! A bit more details on the background:

I am working on a GitHub Action that use markdownlint-cli2 to lint changed Markdown files. This means the lint can be run in any project (JS, Java, Golang...). The problem with using npm install --dev is that for projects managed with yarn, I am hitting this error:

$npm install markdownlint-rule-relative-links@2.1.0 --save-dev
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: jest-config@29.7.0
npm WARN Found: @types/node@20.8.4
npm WARN node_modules/jest-config/node_modules/@types/node
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional @types/node@"*" from jest-config@29.7.0
npm WARN node_modules/jest-config
npm WARN   jest-config@"^29.7.0" from create-jest@29.7.0
npm WARN   node_modules/create-jest
npm WARN   1 more (jest-cli)
npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "link:": link:../app

npm ERR! A complete log of this run can be found in:
npm ERR!     /usr/local/google/home/ziniz/.npm/_logs/2023-10-19T17_27_06_802Z-debug-0.log

So I was thinking to avoid this issue I could use the --global flag, but then there is the issue I mentioned above that the linter cannot find the installed package.

Any suggestion on how I should implement that?

theoludwig commented 8 months ago

Sorry for the late response. From what I understand, your issue have been solved. https://github.com/DavidAnson/markdownlint-cli2/issues/224#issuecomment-1773252499

Will close this issue for now. Feel free to open another issue, if there is something not working with this custom rule. :smile: