-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add ESM Import Compatibility #660
Comments
Thanks for your contribution. I will have a look as soon as possible, when I have the time. |
It still seems there is not ESM compatibility for Showdown in 2020. |
Is this coming? |
Any updates on ESM compatability? |
+1 the dist in closed PR 661 so far works well. |
Another vote for ESM here. I love Showdown, but had to switch away from it for my modules because I can't distribute libraries that leak into the global scope. 😞 |
I'm also waiting for this and starting to think about switching library. |
yeah i think i may have to switch if this doesnt happen soon, which is a shame as i like this library, no idea what to change to either |
Does anyone have an alternative that has ESM Import compat? It's 2023 and I can't seem to find any. :( @LeaVerou what did you switch to? |
Here is the way to import this lib in an ESM: import Showdown from 'showdown'; |
Hello! |
Is there no esm support for browser? |
just using jsDeliver /+esm path or esm.run (async () => {
try {
const Showdown = await import("https://cdn.jsdelivr.net/npm/showdown/+esm");
const converter = new Showdown.default.Converter();
document.querySelector("#d").innerHTML = converter.makeHtml(
`# showdown.js`
);
} catch (e) {
console.error(e.stack);
}
})(); |
For the TypeScript fans: Install showdown
showdown.d.ts
MyComponent.tsx
|
This is a 5 year old problem but it now is a complete block - I can't even consider using this library without ESM support.
@LeaVerou I realise this from 4 years ago, but please let us know you used instead? Everyone else: has anyone forked this to make a modern ESM compatible version? |
The error below can be fixed by adding a failover to TypeError: Cannot set properties of undefined (setting 'showdown') |
This PR should fix the main problem: #1017 |
That's a patch for being able to run in ESM, but it still loads as a side effect attached to the Where @LeaVerou said:
For this to be consumed by ESM libraries it needs to load as a module: import { showdown } from './showdown.esm.js';
// Scoped to module
const converter = new showdown.Converter();
// Must not leak into window or self
if(globalThis.showdown)
throw new ('Global scope polluted',); This allows my library to require |
@KeithHenry I was just looking for an alternative. Not sure if it fits your needs, but markedjs/marked seems to be a good one. |
ESM is coming. It is already supported in most browsers and is coming to Node 1.
With that said, there are few libraries that have native support for it yet. As far as Markdown parsers go:
Long-story-short, unless somebody starts a 'clean room' implementation of a Markdown parser in ES this is going to be a pain point for FE devs working in native ESM.
I've been experimenting a bit and managed to create a PR that adds support with very minimal impact on the existing codebase.
1 I'm a participant on the Node/Modules work group. If all goes well, we may see unflagged support before the end of the year.
The text was updated successfully, but these errors were encountered: