8

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
3
  • maybe you can try npm link typescript? Commented Jul 28, 2021 at 5:16
  • 2
    @Yilmaz Are you using node 12 or 14? i encounter this error on those versions before. The solution of mine is either 1) upgrade to node.js 16 or 2) install and run both ts and ts-node-dev on the fly npx -p typescript -p ts-node-dev ts-node-dev src/main.ts Commented Jul 28, 2021 at 6:51
  • 1
    npx -p typescript -p ts-node-dev ts-node-dev src/main.ts worked me, after installing rxjs. Commented Sep 2, 2021 at 17:47

1 Answer 1

13

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.