highlight.js: ESM build does not export named exports

Describe the issue/behavior that seems buggy

The ESM build does not export named exports.

The highlight code links to the Node docs on how to setup an ESM build: https://github.com/highlightjs/highlight.js/blob/bd548da78a905067a4d5c4c42801c4498df0ee1f/tools/build_node.js#L11

However, it does not appear to follow the instructions mentioned there.

In my experience, the wrapper approach mentioned in the Node docs doesn’t work all that well compared to having Rollup output both formats. I see you’re already using Rollup. Is there any reason you don’t have it output CJS and ESM instead of creating a wrapper?

Sample Code or Instructions to Reproduce

npm install --save highlight.js
cat node_modules/highlight.js/es/core.js

Expected behavior

The individual functions like highlight and registerLanguage should be exported in addition to the default export

Additional context

I can’t get highlight to work in SvelteKit / Vite without workarounds (https://github.com/metonym/svelte-highlight/issues/158)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I can’t get highlight to work in SvelteKit / Vite

I don’t know what this means exactly… does your project fail to build? What is the error? Does it simply fail at runtime, is there a console error, etc?

It’s worth noting the CDN build now also includes ESM libs, I wonder if that might perhaps be of use to you. It is done differently there since we don’t have to take Node idiosyncrasies into account.