Skip to content

Commit

Permalink
fix(swc-loader): swc-loader should now only log when both swc sources…
Browse files Browse the repository at this point in the history
… can't be resolved
  • Loading branch information
DuCanhGH committed Jun 21, 2023
1 parent 080b9b8 commit a47f236
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/utils/src/swc-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ export function swcLoader(this: any, source: string, inputSourceMap: string) {
const sync = programmaticOptions.sync;
const parseMap = programmaticOptions.parseMap;

let swc: Compiler;
try {
// avoid installing @swc/core
swc = require("next/dist/build/swc");
} catch {
logger.info(
"Using @swc/core to compile next-pwa's features. Please install it if you haven't."
let swc: Compiler | undefined;

for (const swcSource of ["next/dist/build/swc", "@swc/core"]) {
try {
swc = require(swcSource);
break;
} catch {
// Do nothing, this swc source might not be available
}
}

if (!swc) {
logger.error(
"Failed to resolve swc. Please install @swc/core if you haven't."
);
swc = require("@swc/core");
process.exit(1);
}

// Remove loader related options
Expand Down

0 comments on commit a47f236

Please sign in to comment.