Skip to content
Nilay Kabariya

Entry No.025·Fixes··3 min read

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.

The error, verbatim

Jump to the fix ↓
enum Color { Red, Green }
^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript enum is not supported in strip-only mode
    at parseTypeScript (node:internal/modules/typescript:68:40)
    at processTypeScriptCode (node:internal/modules/typescript:146:42)

# the same family:
SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript parameter property 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 export assignment is not supported in strip-only mode
SyntaxError [ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX]: TypeScript import equals declaration is not supported in strip-only mode
✓ Reproduced on Windows 11 Pro

Tested on

Node
22.18.0, 24.14.0
tsx
4.23.15
OS
Windows 11 Pro
Contents
  1. The fix01
  2. Which line Node means02
  3. Why it happens03
  4. Which fix to pick04
  5. What didn’t work05
  6. How this was tested06

You ran node file.ts and Node stopped at one line. Your code isn’t wrong. Node just refuses to generate anything, and that line needs generated JavaScript.

The fix

Keep the code as it is, and tell Node to transform it:

node --experimental-transform-types src/index.ts

Node prints this every time you use it:

ExperimentalWarning: Transform Types is an experimental feature and might change at any time

To hide it, add a second flag:

node --experimental-transform-types --disable-warning=ExperimentalWarning src/index.ts

For npm scripts or tools that start Node for you, the flag also works from the environment: NODE_OPTIONS=--experimental-transform-types. I checked that it has the same effect.

Or run it with tsx, which compiles instead of stripping, so none of this syntax is a problem:

npm i -D tsx
npx tsx src/index.ts

Which line Node means

The message names the construct, and the carets under the code point at it. Here’s the whole family, each one reproduced:

The error says Your code has Plain-JavaScript version
enum is not supported enum Color { Red, Green } const Color = { Red: 0, Green: 1 } as const;
parameter property is not supported constructor(private name: string) {} a private name: string; field, set in the constructor
namespace declaration is not supported namespace Config { export const port = 3000; } const Config = { port: 3000 };
export assignment is not supported export = add; (in a .cts file) module.exports = add;
import equals declaration is not supported import path = require("node:path"); const path = require("node:path");

Why it happens

Since Node 22.18, node file.ts works out of the box, but not by compiling. Node deletes the type annotations and runs what’s left. That’s “strip-only mode”.

Most TypeScript survives that. These five don’t, because they don’t disappear when the types are removed: an enum has to become a real object, a parameter property has to become an assignment, a namespace has to become a wrapper. Stripping can’t write that code, so Node stops and names the construct.

--experimental-transform-types switches Node from stripping to actually transforming, which is why the same files run with it.

Which fix to pick

  • One script, or you don’t want to touch working code: the flag. It’s one word in the command.
  • An app you run every day, or you’d rather avoid an experimental flag: tsx.
  • Code that should run on plain node for years: rewrite the few lines using the table above. That’s also the only route with no flag and no dependency.

If you rewrite, turn on erasableSyntaxOnly in tsconfig.json so the type checker flags these before Node does. That produces a different error in your editor: This syntax is not allowed when ‘erasableSyntaxOnly’ is enabled (TS1294), which shows the same rewrites in more detail.

What didn’t work

How this was tested

Five small files, one construct each (enum, a constructor parameter property, a namespace with a value in it, export = in a .cts file, import x = require() in a .cts file), plus a type-only namespace as a control. Each was run with plain node, with --experimental-transform-types, through NODE_OPTIONS, with tsx 4.23.15, and in its rewritten form, on Node 24.14.0. On Node 22.18.0 each ran plain, with the flag, and rewritten. All on Windows 11 Pro. Every error and output above is copied from those runs.

— N.K., end of entry No.025

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.015

    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.

    > src/a.ts(1,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.

    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