Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LinusU opened this issue Nov 18, 2022 · 21 comments · Fixed by #2100
Closed

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

LinusU opened this issue Nov 18, 2022 · 21 comments · Fixed by #2100
Labels

Comments

@LinusU
Copy link

LinusU commented Nov 18, 2022

  • 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

@remy
Copy link
Owner

remy commented Nov 18, 2022

I'm not really familiar with TypeScript (mostly intentionally), but going by the steps you've included, it looks like a good work around would be to not use the ts-code thing if there's NODE_OPTIONS set.

Would that sound about right?

@LinusU
Copy link
Author

LinusU commented Nov 18, 2022

NODE_OPTIONS can be used to pass any options that could also be given to node via passing cli arguments, so potentially it's used for other things where people want the ts-node behaviour. Maybe checking if --loader is present in NODE_OPTIONS is a better approach?

Personally, I would drop ts-node from the default execMap, since there is multiple programs that run .ts file (e.g. Deno). And just inside node there are multiple solutions other than ts-node (e.g. tsx).

I'd be happy to submit a PR for any of the above approaches ☺️

@remy
Copy link
Owner

remy commented 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.

@LinusU
Copy link
Author

LinusU commented Nov 18, 2022

Sounds good 👍

Where in the code do you think it would be best to add the check? In nodemon/lib/config/defaults.js?

I'm thinking something like (process.env.NODE_OPTIONS || '').includes('--loader')

@github-actions
Copy link

github-actions bot commented Dec 2, 2022

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Dec 2, 2022
@LinusU
Copy link
Author

LinusU commented Dec 6, 2022

ping @remy, do you have any thoughts on my last question?

@github-actions github-actions bot removed the stale no activity for 2 weeks label Dec 6, 2022
@github-actions
Copy link

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Dec 20, 2022
@LinusU
Copy link
Author

LinusU commented Dec 20, 2022

friendly ping @remy

@github-actions github-actions bot removed the stale no activity for 2 weeks label Dec 20, 2022
@github-actions
Copy link

github-actions bot commented Jan 3, 2023

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Jan 3, 2023
@LinusU
Copy link
Author

LinusU commented Jan 3, 2023

friendly ping @remy

@github-actions github-actions bot removed the stale no activity for 2 weeks label Jan 3, 2023
@github-actions
Copy link

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Jan 17, 2023
@LinusU
Copy link
Author

LinusU commented Jan 18, 2023

friendly ping @remy

@github-actions github-actions bot removed the stale no activity for 2 weeks label Jan 18, 2023
@github-actions
Copy link

github-actions bot commented Feb 1, 2023

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Feb 1, 2023
@LinusU
Copy link
Author

LinusU commented Feb 1, 2023

friendly ping @remy

Just need to know where you want the code and I'd be happy to send a PR 😅

@github-actions github-actions bot removed the stale no activity for 2 weeks label Feb 1, 2023
@github-actions
Copy link

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Feb 15, 2023
@LinusU
Copy link
Author

LinusU commented Feb 16, 2023

friendly ping @remy

Just need to know where you want the code and I'd be happy to send a PR 😅

@github-actions github-actions bot removed the stale no activity for 2 weeks label Feb 16, 2023
remy added a commit that referenced this issue Feb 16, 2023
@remy
Copy link
Owner

remy commented Feb 16, 2023

Sorry, talk about having to prod me!

You had the solution a good while ago, but it was quicker for me to make the PR! I'll get it merged today.

@LinusU
Copy link
Author

LinusU commented Feb 17, 2023

Hehe, no worries, thanks for fixing this 🙏

Would love to see a release with this in it 🚀

@remy
Copy link
Owner

remy commented Mar 2, 2023

I seem to have lost the PR I was planning to make. Good lord I'm distracted quickly!

@github-actions
Copy link

github-actions bot commented Mar 2, 2023

🎉 This issue has been resolved in version 2.0.21 🎉

The release is available on:

Your semantic-release bot 📦🚀

remy added a commit that referenced this issue Mar 22, 2023
@github-actions
Copy link

🎉 This issue has been resolved in version 2.0.22 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants