Skip to content

Commit

Permalink
refactor(v2): make even better SSR error notify and add tip (#4875)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored Jun 2, 2021
1 parent f35dc69 commit 15d4519
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/docusaurus/src/client/serverEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,21 @@ export default async function render(locals) {
} catch (e) {
console.error(
chalk.red(
`Docusaurus Node/SSR could not render static page with path=${locals.path} because of error: ${e.message}`,
`Docusaurus Node/SSR could not render static page with path "${locals.path}" because of following error:\n\n${e.stack}\n`,
),
);
throw e;

const isNotDefinedErrorRegex = /(window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;

if (isNotDefinedErrorRegex.test(e.message)) {
console.error(
chalk.green(
'Pro tip: It looks like you are using code that should run on the client-side only.\nTo get around it, try using <BrowserOnly> (https://docusaurus.io/docs/docusaurus-core/#browseronly) or ExecutionEnvironment (https://docusaurus.io/docs/docusaurus-core/#executionenvironment).\nIt might also require to wrap your client code in useEffect hook and/or import a third-party library dynamically (if any).',
),
);
}

throw new Error('Server-side rendering fails due to the error above.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function build(
isLastLocale,
});
} catch (e) {
console.error(`error building locale=${locale}`);
console.error(`Unable to build website for locale ${locale}.`);
throw e;
}
}
Expand Down

0 comments on commit 15d4519

Please sign in to comment.