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 showFix it fast
Most common cause, 1 of 3Your own code declares an enum or a namespace with values
Replace the enum with a const object plus a type of its values.
// 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) // 1Short 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.
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.
node --version
npx tsc --noEmit --erasableSyntaxOnlyThen find the line you see in this list and open its fix:
- 1Your own code declares an enum or a namespace with values
The caret in the error points at an enum or namespace line in a file you wrote - 2A class uses constructor parameter properties
The message says parameter property is not supported - 3The enum comes from generated code you do not edit by hand
The 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 modeSyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript namespace declaration is not supported in strip-only modeSyntaxError [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.
grep -rnE '^\s*(export )?(const )?enum |^\s*(export )?namespace ' srcFix
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.
// 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) // 1Verify
Run the file with plain node. It prints the value with no syntax error.
node src/main.tsConfirmed by nodejs.org
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.
grep -rnE 'constructor\((public|private|protected|readonly) ' srcFix
Declare the field and assign it in the constructor yourself.
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.
// tsconfig.json
{ "compilerOptions": { "erasableSyntaxOnly": true, "verbatimModuleSyntax": true } }Confirmed by typescriptlang.org
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.
head -20 src/gql/graphql.ts | grep -n enumFix
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.
# codegen.yml
config:
enumsAsConst: true
# or keep the enums and use a transpiling runner
npm install --save-dev tsx
npx tsx src/main.tsVerify
Regenerate, then run the entry point with node; no ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX appears.
npx graphql-codegen && node src/main.tsConfirmed by the-guild.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.