question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESM build does not export named exports

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Jul 31, 2021

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.

0reactions
benmccanncommented, Oct 17, 2021

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESM Build fails with "Named export not found". #166 - GitHub
I'm providing .mjs files with explicit file imports and exports (extensions included) I'm providing a ... ESM Build fails with "Named export not...
Read more >
The requested module does not provide an export named in JS
The "Ucaught SyntaxError: The requested module does not provide an export named" occurs when mixing up default and named ES6 module imports and...
Read more >
"The requested module ' does not provide an export named ...
I'm going to guess that the package.json in the module's folder doesn't have "type": "module" in it, but your module (obviously) does, since...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
When importing CommonJS modules, the module.exports object is provided as the default export. Named exports may be available, provided by static analysis as...
Read more >
rollup.js
You can export an array from your config file to build bundles from several ... file (see example) --no-esModule Do not add __esModule...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found