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
Import any module from @prismicio/react@2.7.1 into a typical Astro application such as one created using npm create astro@latest.
Run the astro application.
You don't need to use the module, just try to import it:
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)
Versions
Reproduction
Steps to reproduce
npm create astro@latest
.You don't need to use the module, just try to import it:
What is expected?
The module should import and run without error.
What is actually happening?
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.