The error, verbatim
Jump to the fix ↓src/a.ts(1,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
src/a.ts(3,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
src/a.ts(6,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
# and the same code run by Node:
SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode
Tested on
- TypeScript
- 5.9.3
- Node
- 24.14.0
- tsconfig
- module nodenext, strict, erasableSyntaxOnly
- OS
- Windows 11 Pro
Contents
The fix
Four pieces of TypeScript are refused, and each has a direct replacement. All four rewrites below type-check with erasableSyntaxOnly on and run under node src/b.ts with no build step.
Enum alternative: a frozen object plus a matching type
export const Status = { Active: 0, Inactive: 1 } as const;
export type Status = (typeof Status)[keyof typeof Status];
const s: Status = Status.Active; // still works, still type-safeNamespace alternative: an exported object, or just a module
namespace Legacy { ... } becomes:
export const Legacy = { x: 1 };Parameter properties: write real fields
constructor(private name: string) becomes:
class User {
private name: string;
readonly id: number;
constructor(name: string, id: number) {
this.name = name;
this.id = id;
}
}const enum: the same as const object
It’s rejected too, in the same way.
Why it happens
Most TypeScript is just JavaScript with extra annotations. Delete the annotations and you have a working .js file. That’s exactly how Node runs TypeScript now: it blanks out the types and runs what’s left, without compiling anything.
Four constructs don’t survive that, because they have to produce JavaScript rather than disappear:
| Construct | Would need to emit |
|---|---|
enum / const enum |
a lookup object built at runtime |
namespace with code in it |
a wrapper function and an object |
constructor(private x) |
an assignment in the constructor body |
| experimental decorators with metadata | extra runtime calls |
erasableSyntaxOnly makes tsc refuse them up front, so the compiler agrees with the runtime. Without it you find out later, when Node throws ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX on the same file.
Why it appeared in your project without you asking
erasableSyntaxOnly exists so a project can be run directly by Node, and starter templates have been turning it on since TypeScript 5.8. Two ways it usually shows up:
- a new project scaffolded from a current template, where the flag is already in
tsconfig.json - an upgrade that pulls in a shared base config
Nothing in your code changed; the rules did. That’s also why an enum your team has shipped for years suddenly fails.
How to disable erasableSyntaxOnly
If you build with tsc, a bundler, or anything else that emits JavaScript, you don’t need the restriction. Remove it:
{ "compilerOptions": { "erasableSyntaxOnly": false } }Your enums compile as they always did. What you lose is the ability to run a source file directly with node file.ts, because Node still refuses that syntax.
Keep it on if you want files to run without a build step, in scripts, tests or small services. That’s the trade: a build step and enum, or no build step and plain JavaScript shapes.
“Unknown compiler option ‘erasableSyntaxOnly’”
A different error, from the other direction: the flag is in your tsconfig.json, but the TypeScript running it is older than 5.8, which introduced it.
error TS5023: Unknown compiler option 'erasableSyntaxOnly'.
Check which version actually runs, then upgrade it in the project:
npx tsc -v
npm install -D typescript@latestWhat didn’t work
Run it yourself
The project I used is on GitHub, so you can trigger the error on your own machine in under a minute:
git clone https://github.com/nils44344/node-ts-error-repros
cd node-ts-error-repros/03-erasable-syntax-only
npm install && npm run repro
How this was tested
One tsconfig.json with erasableSyntaxOnly on, one file containing an enum, a namespace, a const enum, a declare enum and a class with constructor parameter properties, compiled with TypeScript 5.9.3 and run with Node 24.14.0. Every error line above is real output, including the accepted declare enum.
— N.K., end of entry No.015