Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): add better error message for yarn workspace/monorepo/terser issue #3619

Merged
merged 3 commits into from
Oct 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions packages/docusaurus/src/client/serverEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,34 @@ async function doRender(locals) {
});

// Minify html with https://github.com/DanielRuf/html-minifier-terser
return minify(renderedHtml, {
removeComments: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
minifyJS: true,
});
function doMinify() {
return minify(renderedHtml, {
removeComments: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
minifyJS: true,
});
}

// TODO this is a temporary error affecting only monorepos due to Terser 5 (async) being used by html-minifier-terser,
// instead of the expected Terser 4 (sync)
// TODO, remove this once we upgrade everything to Terser 5 (https://github.com/terser/html-minifier-terser/issues/46)
// See also
// - https://github.com/facebook/docusaurus/issues/3515
// - https://github.com/terser/html-minifier-terser/issues/49
try {
return doMinify(true);
} catch (e) {
if (e.message?.includes("Cannot read property 'replace' of undefined")) {
console.error(
chalk.red(
'\nDocusaurus user: you probably have this known error due to using a monorepo/workspace.\nWe have a workaround for you, check https://github.com/facebook/docusaurus/issues/3515\n',
),
);
}
throw e;
}
}