Skip to content

Commit 8263952

Browse files
authored
feat: Pass module: "unknown" to SWC minfiier (#66817)
### What? Pass `module: "unknown"` to the minifier. ### Why? It can minify both a module and a script. `module: "unknown"` lets the parser to detect the type of the program. The problematic library is `react-pdf` and next.js currently errors with ``` Failed to compile. static/media/pdf.worker.1f09ce21.mjs from Terser x 'import', and 'export' cannot be used outside of module code ,-[56104:1] 56104 | const pdfjsBuild = "0cec64437"; 56105 | 56106 | var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler; 56107 | export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler }; : ^^^^^^ 56108 | 56109 | //# sourceMappingURL=pdf.worker.mjs.map `---- Caused by: 0: failed to parse input file 1: Syntax Error Error: x 'import', and 'export' cannot be used outside of module code ,-[56104:1] ``` ### How? Related: #30237 (reply in thread)
1 parent e7a06be commit 8263952

File tree

1 file changed

+1
-0
lines changed
  • packages/next/src/build/webpack/plugins/terser-webpack-plugin/src

1 file changed

+1
-0
lines changed

packages/next/src/build/webpack/plugins/terser-webpack-plugin/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class TerserPlugin {
146146
: {}),
147147
compress: true,
148148
mangle: true,
149+
module: 'unknown',
149150
}
150151
)
151152

0 commit comments

Comments
 (0)