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

* Helpful error message when monorep Terser issue happens

* remove optional chaining usage for node < 14, as I'm not sure this file is transpiled properly (not TS)

* remove useless doMinify  arg
This commit is contained in:
Sébastien Lorber 2020-10-21 15:36:07 +02:00 committed by GitHub
parent 003b457c88
commit 91256d445e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -120,6 +120,7 @@ async function doRender(locals) {
});
// Minify html with https://github.com/DanielRuf/html-minifier-terser
function doMinify() {
return minify(renderedHtml, {
removeComments: true,
removeRedundantAttributes: true,
@ -130,3 +131,26 @@ async function doRender(locals) {
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();
} catch (e) {
if (
e.message &&
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;
}
}