question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Defaulting to `ts-node` is confusing when using ESM loaders

See original GitHub issue
  • Versions: node@v16.15.1, darwin@21.6.0
  • 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

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
remycommented, Nov 18, 2022

I genuinely don’t care about TS support, but it’s been in nodemon for too long that removing it would probably break expectations.

I think checking the --loader is the best (soft) approach that could solve this issue.

0reactions
LinusUcommented, Dec 20, 2022

friendly ping @remy

Read more comments on GitHub >

github_iconTop Results From Across the Web

running node with loader ts-node/esm.js requires imports to ...
I solved it with these experimental features on Node v14.15.0 . node --loader ts-node/esm --experimental-specifier-resolution=node ...
Read more >
API - ESBuild
To join a set of files together with esbuild, import them all into a single entry point file and bundle just that one...
Read more >
Debug Node.js Apps using Visual Studio Code
Setting up a project for Node.js debugging is straightforward with VS Code providing appropriate launch configuration defaults and snippets. There are a few ......
Read more >
tsup
bundle typescript library with ease. ... By default tsup bundles all import -ed modules but dependencies and ... Read more about esm support...
Read more >
is ts-node es modules by default? : r/typescript - Reddit
You must also ensure node is passed --loader. The ts-node CLI will do this automatically with our esm option. Note: --esm must spawn...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found