ts-node is not recognized as an internal or external command

Cause of error ts-node is not recognized as an internal or external command

One can get this error ts-node is not recognized as an internal or external command while running their js file in the vs code. This can also happen while one is trying to start the command in the terminal npm run dev with including package.json file. The error appears as follows: 

 

 

Solution

The TypeScript execution engine and REPL for Node. js is popularly called ts-node. It JIT converts TypeScript into JavaScript, allowing you to run TypeScript on Node. js without having to first precompile it.

To solve this problem the first solution is by installing ts-node as a global. The code for the same is:

 

npm install -g ts-node

There is another solution also available which we consider better than the solution mentioned above. In the above solution if any other person tries to run your file he/she needs to install ts-node as well on a global level. This may cause problems in running the files if the versions are not the same on the two files. Another way of solving is by locally defining pakage.json and by locally installing the node_modules.

A command called npx will help you to achieve this. The code for the same is:

 

rsp@mn-r:~/node/test/ts-test-1$ npm i ts-node typescript
npm WARN ts-test-1@0.0.0 No description
npm WARN ts-test-1@0.0.0 No repository field.

+ ts-node@6.0.3
+ typescript@2.8.3
added 19 packages from 44 contributors in 2.157s
[+] no known vulnerabilities found [19 packages audited]

 

Now try to run ts-node:

 

rsp@mn-r:~/node/test/ts-test-1$ ts-node -v

-bash: /Users/rsp/opt/node/bin/ts-node: No such file or directory

Now run npx or you can give the oath explicitly also:

 

127!rsp@mn-r:~/node/test/ts-test-1$ npx

ts-node -v
ts-node v6.0.3

node v10.1.0

typescript v2.8.3

 

Also Read: no matching function for call to rctbridgemodulenameforclass

 

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *