Skip to content

How to use ts-node esm loader with npx? #1463

Answered by cspotcode
Maxim-Mazurok asked this question in Q&A
Discussion options

You must be logged in to vote

I think the problem is that npx will install and run an executable into a non-local location controlled by npx, but the working directory is local. Node's --loader flag attempts to import the loader, which will be done locally unless it is an absolute path.

This is why the following:

npx --package ts-node node --loader ts-node/esm ./example.ts

Will raise an error Cannot find package 'ts-node'. ts-node cannot be found in the working directory.

We have a ticket for this: #1258

That ticket proposes the addition of a new executable: ts-node-esm which can be used as follows:

npx --package ts-node ts-node-esm ./example.ts

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@Maxim-Mazurok
Comment options

@cspotcode
Comment options

Answer selected by Maxim-Mazurok
Comment options

You must be logged in to vote
2 replies
@Maxim-Mazurok
Comment options

@sastraxi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants