Unable to load your Astro config
when linked cjs dependency is imported in astro.config.ts
#11621
Labels
- P3: minor bug
An edge case that only affects very specific usage (priority)
requires refactor
Bug, may take longer as fixing either requires refactors, breaking changes, or considering tradeoffs
Astro Info
If this issue only occurs in one browser, which browser is a problem?
NA
Describe the Bug
Related: napi-rs/napi-rs#2206
When cjs linked dependency is imported in
astro.config.ts
, it throws an error since Vite'sssrLoadModule
doesn't support cjs global such asrequire
andmodule
.When such dependency is only used inside app, users can workaround it by explicitly externalizing by
vite.ssr.external
, but that seems impossible whenssrLoadModule
is used when loadingastro.config.ts
itself.What's the expected result?
Config loads successfully.
I'm not so familiar with Astro, but when looking at the code, it looks like it's desired/planned to externalize all deps here. Perhaps, this can be switched to
ssr.external: true
since the linked PR is already merged long time ago.astro/packages/astro/src/core/config/vite-load.ts
Lines 14 to 27 in bc27964
Link to Minimal Reproducible Example
https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vite-ssr-cjs-astro-napi-rs-2206?file=README.md
(note: on stackblitz, it looks like
ssrFixStacktrace
is also crashing so the error log is different. original code can be found in https://github.com/hi-ogawa/reproductions/tree/main/vite-ssr-cjs-astro-napi-rs-2206)Participation
The text was updated successfully, but these errors were encountered: