highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.3k stars 3.52k forks source link

Main branch exhibits breaking changes when markdown-it-highlightjs is upgraded to it from 11.5.1 #4026

Closed aral closed 1 month ago

aral commented 3 months ago

Describe the issue/behavior that seems buggy

It looks like something changed in main that’s breaking the markdown-it-highlightjs plugin when upgraded to it from the version it is currently using (11.5.1)

Specifically, tests pass before the upgrade but when running the tests after an upgrade, I’m seeing:

Error: Cannot find module '/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/highlight.js/lib/index.js'. Please verify that the package.json has a valid "main" entry

(Full stack trace at end.)

Sample Code or Instructions to Reproduce

  1. git clone https://github.com/valeriangalliat/markdown-it-highlightjs.git
  2. cd markdown-it-highlightjs.git
  3. npm i
  4. npm run test and note all tests passing
  5. Change the highlight.js dependency in package.json from 11.5.1 to https://github.com/highlightjs/highlight.js
  6. npm i
  7. npm run test

Expected behavior

Since 11.5.1 →11.9.0 (version in main) is a semver minor update, I’d expect all tests to still pass.

The issue does not exist in the release version of 11.9.0, where all tests pass, so this is either a regression or a breaking change in main.

Actual behavior

Tests fail with error message mentioned above and with full stack trace as provided below.

Additional context

Full stack trace:

Error: Cannot find module '/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/highlight.js/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:450:19)
    at Module._findPath (node:internal/modules/cjs/loader:720:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1135:27)
    at Module._load (node:internal/modules/cjs/loader:990:27)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/var/home/aral/Projects/other/markdown-it-highlightjs/dist/index.js:40:32)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/var/home/aral/Projects/other/markdown-it-highlightjs/index.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/var/home/aral/Projects/other/markdown-it-highlightjs/test/test.js:6:21)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12)
    at cjsLoader (node:internal/modules/esm/translators:359:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:308:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:430:15)
    at async formattedImport (/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/mocha/lib/nodejs/esm-utils.js:7:14)
    at async exports.requireOrImport (/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/mocha/lib/nodejs/esm-utils.js:48:32)
    at async exports.loadFilesAsync (/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/mocha/lib/nodejs/esm-utils.js:103:20)
    at async singleRun (/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async exports.handler (/var/home/aral/Projects/other/markdown-it-highlightjs/node_modules/mocha/lib/cli/run.js:374:5)
joshgoebel commented 3 months ago
❯ ls build/lib/index.js
build/lib/index.js
❯ cat build/package.json| grep main
  "main": "./lib/index.js",

We stil ship this file... if someone else has any more specific details on this failure...

valeriangalliat commented 1 month ago

This appears to be due to installing highlight.js from the GitHub repository as opposed to from the npm registry

Because lib is not built in that context, importing lib does not work

I'm confident it will work in future npm releases of highlight.js :)

Running npm run build as part of the prepare npm script would probably allow installing from GitHub directly if that's something you're keen on supporting

joshgoebel commented 1 month ago

This appears to be due to installing highlight.js from the GitHub repository as opposed to from the npm registry

Yes, our GitHub repo here is the raw (unbuilt) source, it's not meant to be used via npm, etc.


You might have better luck with: https://github.com/highlightjs/cdn-release