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

Node option for experimental and module resolutions #880

Closed
robinglen opened this issue Sep 4, 2019 · 8 comments
Closed

Node option for experimental and module resolutions #880

robinglen opened this issue Sep 4, 2019 · 8 comments

Comments

@robinglen
Copy link

Hello,

I have a project that is written in typescript that imports node modules that are not transpiled. So I want to be able to use both ts-node to handle my code and pass flags to node so I can use native imports.

I thought the following might work:

node --experimental-modules --es-module-specifier-resolution=node --require ts-node/register ./src/server.ts

Unfortunately not, I also saw the following: #560

I was just wondering if there was support for something like this, or if you are still looking for a PR?

Thank you,
Robin

@blakeembrey
Copy link
Member

@thearegee There's a long thread around here where people have commented on possible implementations, but yes - still looking for a PR! Happy to work with you on getting it out.

@robinglen
Copy link
Author

@blakeembrey if you could link the thread, or let me know if there was a preference in approach and maybe give me a point in the right direction I will knock something up tomorrow

I would love to get something like this in because it will make my project so much cleaner

@robinglen
Copy link
Author

I was thinking we need the ability to pass any node flags to ts-node. I looked at some tickets I could find, some looked like they suggested using environmental variables:

NODE_OPTIONS='--experimental-modules --es-module-specifier-resolution=node'

Others seemed to suggest maybe use argv so maybe more like this:

ts-node --node-options '--experimental-modules --es-module-specifier-resolution=node'

First I was wondering if you had a preference of what you would like?

Secondly I was struggling to understand how you were passing the script to node where you could set these flags. I looked into in your bin.js you were using vm and there was potentially a chance you could use importModuleDynamically from: https://nodejs.org/api/vm.html#vm_script_runinnewcontext_sandbox_options

However I didn't see this being executed when I was playing around. So yeah, I'm happy do the work, just need a little guidance on how you expect this to work and some more context.

Thanks,
Rob

@blakeembrey
Copy link
Member

Node flags to TS node is a much different request and we should keep these separate, but I’ll be the first to decline supporting node.js flags in the TS Node executable. If you go through the Git history, you’ll discover that used to be possible - it was just too much to maintain and had some annoying edge cases. Every feature brings more issues/requests so I ended up removing it in favor of using node native features.

@blakeembrey
Copy link
Member

The issue is #436.

@robinglen
Copy link
Author

@blakeembrey so would you be open for both --experimental-modules and --es-module-specifier-resolution=node as apposed allowing for any node flag?

I will catch up on the issue today

@cspotcode
Copy link
Collaborator

@thearegee native module support was implemented and published, and feedback is being tracked in #1007
I think that covers what you wanted here, so I'm closing this. Let me know if you were asking for something else and we can reopen as needed.

@wvhulle
Copy link

wvhulle commented Dec 20, 2022

ts-node --experimentalSpecifierResolution node works for me

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

No branches or pull requests

4 participants