summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2022-07-21 13:45:33 -0500
committerGravatar GitHub <noreply@github.com> 2022-07-21 13:45:33 -0500
commit48011cbcf87894ff2540f06bfbcc83b76f6fb7ff (patch)
tree110b171bed40a28d93e787777aefa4ba5bc5fb75
parent81758f1c1e5cbe6827510e26c553790def05f25e (diff)
downloadastro-48011cbcf87894ff2540f06bfbcc83b76f6fb7ff.tar.gz
astro-48011cbcf87894ff2540f06bfbcc83b76f6fb7ff.tar.zst
astro-48011cbcf87894ff2540f06bfbcc83b76f6fb7ff.zip
fix: provide hint for undefined exports (#4003)
Co-authored-by: Nate Moore <nate@astro.build>
-rw-r--r--packages/astro/src/core/errors.ts4
1 files changed, 3 insertions, 1 deletions
diff --git a/packages/astro/src/core/errors.ts b/packages/astro/src/core/errors.ts
index 39cc8b797..7cfb46e45 100644
--- a/packages/astro/src/core/errors.ts
+++ b/packages/astro/src/core/errors.ts
@@ -88,6 +88,8 @@ export function createCustomViteLogger(logLevel: LogLevel): Logger {
function generateHint(err: ErrorWithMetadata, filePath?: URL): string | undefined {
if (/Unknown file extension \"\.(jsx|vue|svelte|astro|css)\" for /.test(err.message)) {
return 'You likely need to add this package to `vite.ssr.noExternal` in your astro config file.';
+ } else if (err.toString().startsWith('ReferenceError') && (err.loc?.file ?? filePath?.pathname)?.endsWith('.astro')) {
+ return 'export statements in `.astro` files do not have access to local variable declarations, only imported values.';
} else {
const res = incompatPackageExp.exec(err.stack);
if (res) {
@@ -115,7 +117,7 @@ export function collectErrorMetadata(e: any, filePath?: URL): ErrorWithMetadata
err.pluginCode ||
err.id ||
stackText.split('\n').find((ln) => ln.includes('src') || ln.includes('node_modules'));
- const source = possibleFilePath?.replace(/^[^(]+\(([^)]+).*$/, '$1');
+ const source = possibleFilePath?.replace(/^[^(]+\(([^)]+).*$/, '$1').replace(/^\s+at\s+/, '');
const [file, line, column] = source?.split(':') ?? [];
if (!err.loc && line && column) {
err.loc = {