Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks on npx: assumes highlight.js is available locally #13

Closed
geelen opened this issue Sep 12, 2022 · 3 comments
Closed

Breaks on npx: assumes highlight.js is available locally #13

geelen opened this issue Sep 12, 2022 · 3 comments

Comments

@geelen
Copy link

geelen commented Sep 12, 2022

Rather than adding github-readme-to-html as a dev dependency, I've been invoking it using:

npx github-readme-to-html -t npx-import

To build https://npx-import.pages.dev/

But that stopped working after the syntax highlighting stuff got released with the following error:

❯ npx github-readme-to-html -t npx-import
Need to install the following packages:
  github-readme-to-html@1.0.9
Ok to proceed? (y) y
failed to read ./node_modules/highlight.js/styles/github.css
/Users/glen/.npm/_npx/90908b89e457455e/node_modules/github-readme-to-html/index.js:54
      throw err;
      ^

[Error: ENOENT: no such file or directory, open './node_modules/highlight.js/styles/github.css'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: './node_modules/highlight.js/styles/github.css'
}

Node.js v18.3.0

I think this is because you're assuming highlight.js is installed as a dependency of the current directory. To fix it temporarily, I've changed my Pages command to the following:

npm install highlight.js && npx github-readme-to-html -t npx-import

BUT, I think this should be fairly easy to fix. This line https://github.com/jrnewton/github-readme-to-html/blob/main/index.js#L13:

const hljsCssFile = './node_modules/highlight.js/styles/github.css';

Should (I think!) be able to be replaced with:

const hljsCssFile = require.resolve('highlight.js/styles/github.css')

And things should all just work? If it's installed locally, it'll find that, otherwise it should look inside the npx temporary directory to use the copy there.

@jrnewton
Copy link
Owner

lgtm - open a PR and I'll merge it.

@jrnewton
Copy link
Owner

Fixed in 1.0.10

@jrnewton
Copy link
Owner

Thank you @albavilanova for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants