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

Vercel Serverless - astro build fails with "Cannot use import statement outside a module" #6299

Closed
1 task
ref-thomasledoux1 opened this issue Feb 18, 2023 · 3 comments · Fixed by #6317
Closed
1 task
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@ref-thomasledoux1
Copy link

What version of astro are you using?

2.0.14

Are you using an SSR adapter? If so, which one?

Vercel

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

I recently switched from the Edge Vercel adapter to the Serverless Vercel adapter, and I notice the astro build command is now failing.
The error seems to happen during the prerendering phase.
The stacktrace points to dist/index.js, which is a generated file by Astro I suppose, so not sure how this can be fixed.

(node:30558) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
error   Cannot use import statement outside a module
/Users/thomas_ledoux/Documents/Projects/website-thomas-astro/dist/entry.js:1
import { performance } from 'node:perf_hooks';
^^^^^^

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)

My codesandbox didn't want to work when sharing it, so I just added the Github link to the right branch.

Link to Minimal Reproducible Example

https://github.com/thomasledoux1/website-thomas-astro/tree/feature/add-auth-comment-overview

Participation

  • I am willing to submit a pull request for this issue.
@ref-thomasledoux1
Copy link
Author

Extra info: switched to Netlify adaptor and issue doesn’t occur anymore. So had something to do with Vercel Serverless adaptor

@wbjohn
Copy link
Contributor

wbjohn commented Feb 19, 2023

Did you try adding "type": "module" in your package.json?

@thomasledoux1
Copy link

Weirdly, this did fix the issue.
I wonder why it does work with the exact same setup with the Netlify adaptor though?
Maybe this should be added to the docs if it would really be necessary to add this line to your package.json?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants