Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ts-node-dev runs into an error: "Cannot find module 'typescript'"

I am trying to set up a basic nest.js app.

main.js is in the src folder. I run this command:

  npx ts-node-dev src/main.ts

I get this error:

Cannot find module 'typescript'
Require stack:
- /home/yilmaz/.npm/_npx/429895/lib/node_modules/ts-node-dev/lib/index.js
- /home/yilmaz/.npm/_npx/429895/lib/node_modules/ts-node-dev/lib/bin.js

I installed typescript globally, close the terminal and restart it. run tsc -v and I get "Version 4.3.5" but the error is not resolved.

This is the tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2017",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

After I installed typescript, I recreated this file with tsc --init and enabled

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
like image 978
Yilmaz Avatar asked Jun 15 '26 23:06

Yilmaz


1 Answers

I had this problem myself and even tough I didn't clearly understand the main cause, I did the following stuff and it worked out.

So basically I have installed the ts-node-dev package as a dev dependency(npm i --save-dev ts-node-dev), and after that was running into another error regarding rxjs, so I just installed that too as a dependency(npm i rxjs) and after that it worked ts-node-dev as well as npx ts-node-dev

like image 155
Ion Harea Avatar answered Jun 19 '26 00:06

Ion Harea



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!