Next.js Discord

Discord Forum

Baffling compile error out of nowhere - 'import', and 'export' cannot be used outside of module code

Unanswered
Sinhala Hound posted this in #help-forum
Open in Discord
Avatar
Sinhala HoundOP
This error started happening out of nowhere - is there some workaround?

static/media/thread.4bee11a3.js from Terser
  x 'import', and 'export' cannot be used outside of module code
   ,-[1:1]
 1 | import crypto from 'node:crypto';
   : ^^^^^^
 2 | import {parentPort} from 'node:worker_threads';
 3 | 
 4 | parentPort.on('message', ({id, value: {algorithm, buffer}}) => {
   `----

Caused by:
    0: failed to parse input file
    1: Syntax Error
Error: 
  x 'import', and 'export' cannot be used outside of module code
   ,-[1:1]
 1 | import crypto from 'node:crypto';
   : ^^^^^^
 2 | import {parentPort} from 'node:worker_threads';
 3 | 
 4 | parentPort.on('message', ({id, value: {algorithm, buffer}}) => {
   `----

9 Replies

Avatar
Sinhala HoundOP
If I disable swcMinifier the error goes away - but that's not really a solution
Avatar
Sinhala HoundOP
bump - anyone? This came out of nowhere, and it's persisting. I can't be the only one
Avatar
Double-striped Thick-knee
can you create a minimal reproduction
Avatar
Sinhala HoundOP
If I knew what was causing maybe?
What I've pasted is the entirety of the error
There is no other information
❯ npm run build-with-build-id

> bcai-web@1.14.0 build-with-build-id
> BUILD_ID=$(git rev-parse HEAD) next build

  ▲ Next.js 14.2.11
  - Environments: .env
  - Experiments (use with caution):
    · swrDelta
    · staleTimes

   Creating an optimized production build ...
Failed to compile.

static/media/thread.4bee11a3.js from Terser
  x 'import', and 'export' cannot be used outside of module code
   ,-[1:1]
 1 | import crypto from 'node:crypto';
   : ^^^^^^
 2 | import {parentPort} from 'node:worker_threads';
 3 | 
 4 | parentPort.on('message', ({id, value: {algorithm, buffer}}) => {
   `----

Caused by:
    0: failed to parse input file
    1: Syntax Error
Error: 
  x 'import', and 'export' cannot be used outside of module code
   ,-[1:1]
 1 | import crypto from 'node:crypto';
   : ^^^^^^
 2 | import {parentPort} from 'node:worker_threads';
 3 | 
 4 | parentPort.on('message', ({id, value: {algorithm, buffer}}) => {
   `----

Caused by:
    0: failed to parse input file
    1: Syntax Error


> Build failed because of webpack errors
Avatar
Sinhala HoundOP
It appears this was from just having included apollo-client in the project...
What a useless error