Search code examples
npm-packageastrojs

Import and use NPM package (Sluggo) in Astro


I want to use this NPM package, Sluggo (https://www.npmjs.com/package/sluggo), in Astro, in the frontmatter of an Astro component.

After installation, I import it following Astro docs:

import { sluggo } from 'sluggo';

When I try to use it following Sluggo docs:

var sluggedString = sluggo('@ monkey\'s are elab؉؉orate fools##');

I get this error: vite_ssr_import_1.sluggo is not a function

I can understand that "sluggo" is not a function, but how can I access the function inside the package?


Solution

  • It looks like sluggo is not a named export, so you need to do:

    import sluggo from 'sluggo';