prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

fix: Specifies type of package as module #201

Open DKFN opened 3 months ago

DKFN commented 3 months ago

In the process of changing framework from Gatsby to Astro, I have stumbled on a build error while using React SSR with astro using this package.

22:57:28 [ERROR] Cannot use import statement outside a module
  Stack trace:
    at internalCompileFunction (node:internal/vm:73:18)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)

Description

This change involves specifying the type of the package to module, wich seems to be the intended type.

Linking this package locally and setting a component using the prismicio to render with SSR works great, for example:

import {PrismicImage} from "@prismicio/react";

const serializer = {
    image: ({node}) => renderToString(<PrismicImage field={node} />)
}

It also keep working for clientside only rendered components.

Resolves: #193

Checklist:

Thanks for your time :)

Instead of an animal or car picture, here is a smiling EN57 image Pic by MOs810 on Wikimedia