Skip to content
Nilay Kabariya

Entry No.015·Fixes·Updated ·3 min read

Fix: This syntax is not allowed when 'erasableSyntaxOnly' is enabled

TS1294: TypeScript rejects your enum, namespace or constructor shorthand. Why new projects turn this on, what each piece becomes, and when to switch it off.

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
✓ Reproduced on Windows 11 Pro

Tested on

TypeScript
5.9.3
Node
24.14.0
tsconfig
module nodenext, strict, erasableSyntaxOnly
OS
Windows 11 Pro
Contents
  1. The fix01
  2. Why it happens02
  3. Why it appeared in your project without you asking03
  4. How to disable erasableSyntaxOnly04
  5. “Unknown compiler option ‘erasableSyntaxOnly’”05
  6. What didn’t work06
  7. Run it yourself07
  8. How this was tested08

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-safe

Namespace 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@latest

What 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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.025

    Fix: TypeScript enum is not supported in strip-only mode

    Node's ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX for enum, parameter properties, namespace, export = and import =. Two ways to run it unchanged, both tested.

    > enum Color { Red, Green }

    FIXED3 min
  2. No.014

    Fix: ERR_MODULE_NOT_FOUND Cannot find module in ES modules

    Node can't find a file that is clearly there. What ES modules changed about relative imports, why TypeScript path aliases break at runtime, and what to change.

    > node:internal/modules/esm/resolve:275

    FIXED2 min
  3. No.013

    Fix: Unknown file extension ".ts" (ERR_UNKNOWN_FILE_EXTENSION)

    Node refuses to run your TypeScript file. The version where this stops happening, what ts-node has to do with it, and the one-line way to run .ts today.

    > node:internal/modules/esm/get_format:189

    FIXED3 min

Post card · Newsletter

Get the next fix in your inbox.

One short email when a new entry is published. No spam, never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text