diff options
author | 2025-03-21 14:01:57 +0000 | |
---|---|---|
committer | 2025-03-21 14:01:57 +0000 | |
commit | 8b5e4dc733bccce7d77defdbb973204aa9b8126b (patch) | |
tree | b4267e8f0e12b8599ab961669502d595274fcb47 | |
parent | e9e9245c7c0ad6e3bda2b7600ff2bd845921a19d (diff) | |
download | astro-8b5e4dc733bccce7d77defdbb973204aa9b8126b.tar.gz astro-8b5e4dc733bccce7d77defdbb973204aa9b8126b.tar.zst astro-8b5e4dc733bccce7d77defdbb973204aa9b8126b.zip |
fix: better error handling on Stackblitz (#13484)
* fix: better error handling on Stackblitz
* Remove unused imports
-rw-r--r-- | .changeset/twelve-gifts-attend.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/config/vite-load.ts | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/.changeset/twelve-gifts-attend.md b/.changeset/twelve-gifts-attend.md new file mode 100644 index 000000000..ccc27dde1 --- /dev/null +++ b/.changeset/twelve-gifts-attend.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Display useful errors when config loading fails because of Node addons being disabled on Stackblitz diff --git a/packages/astro/src/core/config/vite-load.ts b/packages/astro/src/core/config/vite-load.ts index cf6e4a0b0..d6b86b02e 100644 --- a/packages/astro/src/core/config/vite-load.ts +++ b/packages/astro/src/core/config/vite-load.ts @@ -34,6 +34,13 @@ export async function loadConfigWithVite({ const config = await import(pathToFileURL(configPath).toString() + '?t=' + Date.now()); return config.default ?? {}; } catch (e) { + // Normally we silently ignore loading errors here because we'll try loading it again below using Vite + // However, if the error is because of addons being disabled we rethrow it immediately, + // because when this happens in Stackblitz, the Vite error below will be uncatchable + // and we want to provide a more helpful error message. + if (e && typeof e === 'object' && 'code' in e && e.code === 'ERR_DLOPEN_DISABLED') { + throw e; + } // We do not need to throw the error here as we have a Vite fallback below debug('Failed to load config with Node', e); } |