0

I have a TypeScript Node.js project that uses:

  • Experimental decorators ("experimentalDecorators": true)
  • Emit decorator metadata ("emitDecoratorMetadata": true)
  • ES modules ("module": "NodeNext" and "moduleResolution": "NodeNext")
  • TypeORM entities with decorators

My build setup includes:

  • A tsconfig.json configured with the above compiler options.
  • A build script that runs tsc --build (the TypeScript compiler).
  • A start script that runs something like:
    tsc-watch --onSuccess "node dist/src/server.js" --onFailure "echo Cannot compile."
    

When I run npm start, everything works perfectly - the app runs without any errors.

However, when trying to debug the project in VS Code, using ts-node, tsx, or similar approaches, I encounter errors such as unknown .ts file extensions, decorator metadata not loading, or ES module import issues.

I tried several VS Code launch.json configurations, including:

{
  "type": "node",
  "request": "launch",
  "name": "Debug Server",
  "runtimeArgs": ["--loader", "ts-node/esm"],
  "program": "${workspaceFolder}/src/server.ts",
  "sourceMaps": true,
  "skipFiles": ["<node_internals>/**"]
}

The server actually starts, but then TypeORM fails with:

No metadata for "X" was found.

This is how the data source is created:

const ds = new DataSource({
  ...
  entities: ['dist/src/entity/**/*.js'],
  subscribers: ['dist/src/subscriber/**/*.js']
});

Why might decorator metadata not be loaded correctly when running via ts-node/esm even if the server starts?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.