Skip to content

Defaulting to ts-node is confusing when using ESM loaders #2083

Closed
@LinusU

Description

@LinusU
  • Versions: [email protected], [email protected]
  • nodemon -v: 2.0.20
  • Operating system/terminal environment (powershell, gitshell, etc): macOS, Terminal.app, zsh
  • Using Docker? What image: no
  • Command you ran: NODE_OPTIONS='--loader @esbuild-kit/esm-loader' nodemon src/server.ts

Expected behaviour

I was expecting @esbuild-kit/esm-loader being used to load my TypeScript files, as that is the case when I run NODE_OPTIONS='--loader @esbuild-kit/esm-loader' node src/server.ts (same command but with node instead of nodemon).

Actual behaviour

It uses ts-node in order to transpile the TypeScript files.

I only noticed this because source maps wasn't working properly, and upon investigating that I realised that nodemon had actually used ts-node to transpile the typescript files.

Steps to reproduce

  1. Create the following package.json file
    {
      "type": "module",
      "dependencies": {
        "@esbuild-kit/esm-loader": "^2.5.0",
        "nodemon": "^2.0.20"
      }
    }
  2. Run npm install
  3. Create the following index.ts file:
    const test = (foo: string) => { throw new Error(foo) }
    
    test('foo')
  4. Run NODE_OPTIONS='--loader @esbuild-kit/esm-loader' node index.ts
  5. Observe nice stack trace
  6. Run NODE_OPTIONS='--loader @esbuild-kit/esm-loader' nodemon index.ts
  7. failed to start process, "ts-node" exec not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions