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.

Use ts-node locally from node_modules

See original GitHub issue

Hi,

I there a way to use ts-node cli tool locally (from node_modules) ? I would like to be able to run node_modules/.bin/ts-node src/index.ts instead of using it globally.

This will help to manage deferent ts-node versions for deferent projects.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
dannyhulycommented, Dec 20, 2017

I have found the solution in any case.

$ node_modules/ts-node/dist/bin.js src/index.ts

I didn’t noticed that the "bin" file is located in the dist directory. I think that a "bin" file in the node_modules/.bin directory will be a bit more user friendly, but its semantics at this point.

8reactions
stelcheckcommented, Dec 20, 2017

You can create an npm script in your project as follow:

{
  "scripts": {
    "ts-node": "ts-node"
  }
}

And then call

npm run ts-node

Only drawback of this method is that you need to escape flags:

npm run ts-node -- --v8-flag-or-something

However, if you do not use flags like that (just a file name, for instance), you can simply do:

npm run ts-node my-filename.ts

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ts-node - npm
Tip: Installing modules locally allows you to control and share the versions through package.json . ts-node will always resolve the compiler ...
Read more >
Installation | ts-node - TypeStrong · GitHub
Tip: Installing modules locally allows you to control and share the versions through package.json. ts-node will always resolve the compiler from cwd before ......
Read more >
How To Run TypeScript Scripts with ts-node - DigitalOcean
In this article you will learn how to run TypeScript scripts without the hassle of manually transpiling.
Read more >
How to run a ts script installed in node_modules with ts-node
1 Answer 1 · Make sure that you have "esModuleInterop": true in both tsconfigs - in mypackage and in dependent project where you...
Read more >
How to use TypeScript with Node.js - Section.io
When using Ts-node, make sure you have Typescript installed in your local project. To install it, run npm install -D typescript . Go...
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