prismic-dom icon indicating copy to clipboard operation
prismic-dom copied to clipboard

Cannot destructure RichText when importing PrismicDOM

Open flayks opened this issue 4 years ago • 6 comments

When trying to destructure PrismicDOM like that:

import { RichText } from 'prismic-dom'

I get this error:

The requested module '../../_snowpack/pkg/prismic-dom.js' does not provide an export named 'RichText'

Using Snowpack 3

flayks avatar Jan 19 '21 12:01 flayks

Hey @flayks, nice catch!

I was able to reproduce on my end with Snowpack 3, not sure what could cause that though, perhaps because the package is built with webpack?

lihbr avatar Jan 19 '21 16:01 lihbr

@lihbr not quite sure, maybe it needs to be exported as a ES module?

flayks avatar Jan 19 '21 16:01 flayks

More generally the plugin doesn't seem to be compatible with an ESM environment, as using it with SvelteKit, I got imports errors from Vite:

TypeError: Cannot destructure property 'RichText' of '__vite_ssr_import_2__.default' as it is undefined.

Any solutions to that?

flayks avatar Apr 15 '21 17:04 flayks

Hey @flayks, I'm really sorry we didn't manage to make progress on that one since January.

Are you still able to use the prismic-dom package without destructuring it though?

We should be reworking those helpers pretty soon, changing their bundler also :)

cc @samlfair

lihbr avatar Apr 15 '21 21:04 lihbr

No worries. Since SvelteKit went with Vite, unfortunately no, it is not really working as it. Oh ok, cool! That would be nice.

flayks avatar Apr 15 '21 21:04 flayks

Hey, sorry for the late notice: we've been making great progress on revamping our kits!

I think you'd be interested to give a try to @prismicio/helpers@alpha, our revamp of prismic-dom which should allow proper import of everything ☺️

I know we also have an example of using Prismic x Svelte on the way with our new kits, cc @priyaprafful

lihbr avatar Jul 06 '21 15:07 lihbr