From ac2bea7d875d4829deb2816b3c3e2afcfb90c50e Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 7 Sep 2023 10:02:46 -0500 Subject: [PATCH] fix(core): prettier 3 shouldn't cause errors due to esm + compile cache (#19042) (cherry picked from commit f1be92e3df930c6a2246d85ded80394b0ddd8ad3) --- packages/nx/bin/nx.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nx/bin/nx.ts b/packages/nx/bin/nx.ts index 8755ad02ae3b1..c1678c45970f8 100644 --- a/packages/nx/bin/nx.ts +++ b/packages/nx/bin/nx.ts @@ -51,7 +51,17 @@ function main() { process.env.NX_DAEMON = 'false'; require('nx/src/command-line/nx-commands').commandsObject.argv; } else { - if (workspace && workspace.type === 'nx') { + // v8-compile-cache doesn't support ESM. Attempting to import ESM + // with it enabled results in an error that reads "Invalid host options". + // + // Angular CLI, and prettier both use ESM so we need to disable it in these cases. + if ( + workspace && + workspace.type === 'nx' && + !['format', 'format:check', 'format:write', 'g', 'generate'].some( + (cmd) => process.argv[3] === cmd + ) + ) { require('v8-compile-cache'); } // polyfill rxjs observable to avoid issues with multiple version of Observable installed in node_modules