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

Unable to import into an Astro application #193

Open
JamieMason opened this issue Jul 18, 2023 · 1 comment · May be fixed by #201
Open

Unable to import into an Astro application #193

JamieMason opened this issue Jul 18, 2023 · 1 comment · May be fixed by #201
Labels
bug Something isn't working

Comments

@JamieMason
Copy link

JamieMason commented Jul 18, 2023

Versions

  • @prismicio/react: 2.7.1
  • react: N/A
  • node: 18.15.0

Reproduction

git clone https://github.com/JamieMason/prismic-astro-esm-issue-repro
cd prismic-astro-esm-issue-repro
open http://localhost:3000
npm install
npm run dev

Steps to reproduce

  1. Import any module from @prismicio/[email protected] into a typical Astro application such as one created using npm create astro@latest.
  2. Run the astro application.

You don't need to use the module, just try to import it:

---
import { PrismicRichText } from '@prismicio/react';

console.log(PrismicRichText);
---

<p>Some JSX</p>

What is expected?

The module should import and run without error.

What is actually happening?

node_modules/@prismicio/react/dist/index.js:1
import { PrismicProvider } from "./PrismicProvider.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Possible cause

I suspect the project may not be packaged correctly, a tool like https://arethetypeswrong.github.io/?p=%40prismicio%2Freact%402.7.1 can help diagnose the problems:

There is more information here from them on the kinds of issues it picks up and how to resolve them.

Other information

Astro uses Rollup as its bundler.

@JamieMason JamieMason added the bug Something isn't working label Jul 18, 2023
@DKFN DKFN linked a pull request Jan 18, 2024 that will close this issue
7 tasks
@traviswimer
Copy link

What's the status on this? Will the open pull request be merged or is there some problem with making this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants