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

Provide esm version #173

Open
tobiasdiez opened this issue Mar 4, 2023 · 8 comments
Open

Provide esm version #173

tobiasdiez opened this issue Mar 4, 2023 · 8 comments

Comments

@tobiasdiez
Copy link

With more and more build tools (vite, nuxt, etc) going towards an esm-first build, it would be nice if a proper esm interface could be provided, i.e. transpile and distribute esm version, including correct export declaration in package.json.

@michaelhays
Copy link

michaelhays commented Mar 20, 2023

Found a few PRs that seem to address this: #43, #160, #171

For those of you using TypeScript and "type": "module", I'm using this as a workaround:

/imports/slugify.ts

/**
 * Hack to make 'slugify' import work with "type": "module".
 */
import slugify from 'slugify'

export default slugify as unknown as typeof slugify.default

/src/someFile.ts

import slugify from '~/imports/slugify.js'

const slug = slugify('Some Name')

@tyteen4a03
Copy link

+1 on this!

@kmturley
Copy link

Another alternative is to disable TypeScript checking for that line:

// @ts-ignore
slugify('some string')

Although this is not ideal

@glorat
Copy link

glorat commented Aug 13, 2024

I've dealt with this in my typescript project by in-sourcing slugify and converting the code to typescript. See https://gist.github.com/glorat/5070ebd2fa275e2012a51300329a7a55

In-sourcing is de-facto a hard fork but the codebase is mature so wouldn't be an issue for most cases

@realityking
Copy link
Contributor

I just rebased #43. Happy to rework that with full ESM support if I get a 👍 from the maintainers on the approach.

@Trott
Copy link
Collaborator

Trott commented Jan 18, 2025

I don't have a strong opinion one way or other on what to do here. (The use-rollup-to-get-to-ESM approach seems fine to me, as long as @simov is OK maintaining it going forward.) But here's some additional information/context:

  • slug is a nearly-identical module that is ESM and has a proper export statement. (Disclaimer: I'm the owner/maintainer of slug. But I'm also technically a maintainer--but not the owner--of slugify too, so... 🤷 )
  • I'm probably not telling everyone something they don't already know, but just in case: slugify will work with ESM, at least in recent versions of Node.js. And it seems to be shipping with TS types defined, so I would imagine a lot (all?) of the TypeScript issues described previously in this issue have perhaps been solved.

@simov
Copy link
Owner

simov commented Jan 20, 2025

Thanks for your effort @realityking, I'm fine with it too, @Trott.

@realityking
Copy link
Contributor

Fantastic. I'll work on it this week and tag both of you for a review when I'm ready.

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

8 participants