Skip to content

Node option for experimental and module resolutions #880

Closed

Description

@robinglen

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

Activity

  1. blakeembrey commented on Sep 4, 2019

    @blakeembrey
    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.

  2. robinglen commented on Sep 4, 2019

    @robinglen
    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

  3. robinglen commented on Sep 5, 2019

    @robinglen
    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

  4. blakeembrey commented on Sep 6, 2019

    @blakeembrey
    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.

  5. blakeembrey commented on Sep 6, 2019

    @blakeembrey
    Member

    The issue is #436.

  6. robinglen commented on Sep 6, 2019

    @robinglen
    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

  7. cspotcode commented on Jul 29, 2020

    @cspotcode
    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.

  8. wvhulle commented on Dec 20, 2022

    @wvhulle

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions