summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2022-05-12 10:29:59 -0600
committerGravatar GitHub <noreply@github.com> 2022-05-12 10:29:59 -0600
commite48aa2fd1ee4a3637647990182e1f3aa9384e259 (patch)
treedba9e9530ab432256d40e69c47205d0436eb0499
parent8666f22a0f845973de28cddd358861f65981f168 (diff)
downloadastro-e48aa2fd1ee4a3637647990182e1f3aa9384e259.tar.gz
astro-e48aa2fd1ee4a3637647990182e1f3aa9384e259.tar.zst
astro-e48aa2fd1ee4a3637647990182e1f3aa9384e259.zip
add error hints (#3350)
* add error hints * chore: add changeset Co-authored-by: Nate Moore <nate@skypack.dev>
-rw-r--r--.changeset/dry-glasses-guess.md5
-rw-r--r--packages/astro/src/core/errors.ts10
-rw-r--r--packages/astro/src/core/messages.ts4
3 files changed, 19 insertions, 0 deletions
diff --git a/.changeset/dry-glasses-guess.md b/.changeset/dry-glasses-guess.md
new file mode 100644
index 000000000..81b4ac2e6
--- /dev/null
+++ b/.changeset/dry-glasses-guess.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Improve error hints for packages that should be added to `vite.ssr.noExternal`
diff --git a/packages/astro/src/core/errors.ts b/packages/astro/src/core/errors.ts
index 0150978dc..2b1be3a3a 100644
--- a/packages/astro/src/core/errors.ts
+++ b/packages/astro/src/core/errors.ts
@@ -9,6 +9,7 @@ export interface ErrorWithMetadata {
[name: string]: any;
message: string;
stack: string;
+ hint?: string;
id?: string;
frame?: string;
plugin?: string;
@@ -40,6 +41,13 @@ export function fixViteErrorMessage(_err: unknown, server: ViteDevServer) {
return err;
}
+function generateHint(err: ErrorWithMetadata): string | undefined {
+ if (/Unknown file extension \"\.(jsx|vue|svelte|astro)\" for /.test(err.message)) {
+ return 'You likely need to add this package to `vite.ssr.noExternal` in your astro config file.';
+ }
+ return undefined;
+}
+
/**
* Takes any error-like object and returns a standardized Error + metadata object.
* Useful for consistent reporting regardless of where the error surfaced from.
@@ -70,9 +78,11 @@ export function collectErrorMetadata(e: any): ErrorWithMetadata {
if (pluginName) {
err.plugin = pluginName;
}
+ err.hint = generateHint(err);
return err;
}
// Generic error (probably from Vite, and already formatted)
+ e.hint = generateHint(e);
return e;
}
diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts
index 38f9d78f5..e96dd4bb1 100644
--- a/packages/astro/src/core/messages.ts
+++ b/packages/astro/src/core/messages.ts
@@ -212,6 +212,10 @@ export function formatConfigErrorMessage(err: ZodError) {
export function formatErrorMessage(_err: Error, args: string[] = []): string {
const err = collectErrorMetadata(_err);
args.push(`${bgRed(black(` error `))}${red(bold(padMultilineString(err.message)))}`);
+ if (err.hint) {
+ args.push(` ${bold('Hint:')}`);
+ args.push(yellow(padMultilineString(err.hint, 4)));
+ }
if (err.id) {
args.push(` ${bold('File:')}`);
args.push(red(` ${err.id}`));