Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4133 pages
Node.js, PHP and APIs

node file.ts stops with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX on an enum, namespace or constructor

Your error

SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode2 more lines it can show

Fix it fast

Most common cause, 1 of 3

Your own code declares an enum or a namespace with values

Replace the enum with a const object plus a type of its values.

Fix
// before
// enum Color { Red, Green }

// after
export const Color = { Red: 0, Green: 1 } as const
export type Color = (typeof Color)[keyof typeof Color]

console.log(Color.Green) // 1
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Recent Node.js versions run .ts files by deleting the type annotations, and that only works for syntax that can be erased. An enum, a namespace with runtime values or a constructor parameter property needs real code generation, so Node.js throws ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. Rewrite those parts as plain objects and fields, or run the file through tsx or tsc.

  • Applies to Node.js 24.21, TypeScript 7.0
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Check the Node.js version and let the TypeScript compiler list every construct Node.js cannot erase. With erasableSyntaxOnly (TypeScript 5.8 and later) each one is reported as error TS1294.

Run this first
node --version
npx tsc --noEmit --erasableSyntaxOnly

Then find the line you see in this list and open its fix:

  1. 1Your own code declares an enum or a namespace with valuesThe caret in the error points at an enum or namespace line in a file you wrote
  2. 2A class uses constructor parameter propertiesThe message says parameter property is not supported
  3. 3The enum comes from generated code you do not edit by handThe failing file is a generated one, such as GraphQL Code Generator output

What does the error look like?

  • SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode
  • SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript namespace declaration is not supported in strip-only mode
  • SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript parameter property is not supported in strip-only mode

Cause 1 of 3

Your own code declares an enum or a namespace with values

You seeThe caret in the error points at an enum or namespace line in a file you wrote

Check

Since v23.6.0 and v22.18.0, Node.js runs .ts files without a flag by replacing types with whitespace. The docs name enums, namespaces with runtime code, parameter properties and import aliases as the features that need transformation and therefore fail.

Check
grep -rnE '^\s*(export )?(const )?enum |^\s*(export )?namespace ' src

Fix

Replace the enum with a const object plus a type of its values. Behaviour stays the same for string and number lookups, and the file becomes erasable.

Fix
// before
// enum Color { Red, Green }

// after
export const Color = { Red: 0, Green: 1 } as const
export type Color = (typeof Color)[keyof typeof Color]

console.log(Color.Green) // 1

Verify

Run the file with plain node. It prints the value with no syntax error.

Verify
node src/main.ts

Confirmed by nodejs.org

Did this fix it?

Cause 2 of 3

A class uses constructor parameter properties

You seeThe message says parameter property is not supported

Check

constructor(private name: string) is shorthand that makes TypeScript write this.name = name for you. With type stripping nobody writes that line, so Node.js rejects it.

Check
grep -rnE 'constructor\((public|private|protected|readonly) ' src

Fix

Declare the field and assign it in the constructor yourself.

Fix
class Person {
  private name: string
  constructor(name: string) {
    this.name = name
  }
}

Verify

Turn on erasableSyntaxOnly in tsconfig so the compiler flags any new case before Node.js does.

Verify
// tsconfig.json
{ "compilerOptions": { "erasableSyntaxOnly": true, "verbatimModuleSyntax": true } }

Confirmed by typescriptlang.org

Did this fix it?

Cause 3 of 3

The enum comes from generated code you do not edit by hand

You seeThe failing file is a generated one, such as GraphQL Code Generator output

Check

Generators often emit TypeScript enums by default. Editing the output is pointless because the next run puts the enum back.

Check
head -20 src/gql/graphql.ts | grep -n enum

Fix

Ask the generator for erasable output. GraphQL Code Generator's typescript plugin has enumsAsConst and enumsAsTypes for this. When a generator has no such option, run the project with a full TypeScript runner such as tsx instead of plain node.

Fix
# codegen.yml
config:
  enumsAsConst: true

# or keep the enums and use a transpiling runner
npm install --save-dev tsx
npx tsx src/main.ts

Verify

Regenerate, then run the entry point with node; no ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX appears.

Verify
npx graphql-codegen && node src/main.ts

Confirmed by the-guild.dev

Did this fix it?

How do I stop it coming back?

  • Set erasableSyntaxOnly and verbatimModuleSyntax in tsconfig for any code that Node.js runs directly.
  • Prefer const objects with as const over enums in new code.
  • Pin the Node.js version in CI, because type stripping behaviour changed across 22, 23, 24 and 26.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.