7

I am moving from nodemon to ts-node-dev but I am not able to run my index.ts file using ts-node-dev.

I did the following:

  1. yarn add ts-node-dev --dev

  2. In my package.json I have:

    "devDependencies": {
       ...
       "nodemon": "^1.19.2",
       "ts-node": "8.3.0",
       "ts-node-dev": "^1.0.0-pre.56",
       "typescript": "3.6.3"
    }
    

If I run ts-node-dev or ts-node-dev src/index.ts I get the error: command not found: ts-node-dev

What am I doing wrong? It seems to me that is correctly installed.

My scripts

   "scripts": {
      "start": "nodemon --exec ts-node src/index.ts",
      "dev": "ts-node-dev src/index.ts"
   }
Magofoco
  • 5,098
  • 6
  • 35
  • 77

2 Answers2

15

You have 3 options here:

  1. Run the command from actual path:
./node_modules/.bin/ts-node-dev src/index.ts
  1. Use npx
npx ts-node-dev src/index.ts
  1. Install the package globally (wouldn't recommend)
npm i -g ts-node-dev src/index.ts
ts-node-dev src/index.ts
g2jose
  • 1,367
  • 1
  • 9
  • 11
  • I tried 1) and 2) and they give me the same issue. It outputs on my terminal `Using ts-node version 8.10.2, typescript version 3.6.3` for few seconds, then it exits my terminal – Magofoco Aug 03 '20 at 21:41
  • What does your script look like? What is it supposed to do? Does adding a `console.log` and re-running print anything? – g2jose Aug 03 '20 at 21:45
  • Add the info to the original question – Magofoco Aug 03 '20 at 21:47
  • If I use option 1 and run: "./node_modules/.bin/ts-node ./setup-scripts/init-db.ts" it works. But if I run "npm run db-init" which points to the above line in package.json I get an error. '.' is not recognized as an internal or external command, operable program or batch file. Any idea why? – MadMac Dec 11 '20 at 02:24
  • why option.3 is not recommended? – Elect2 Apr 03 '23 at 15:59
0

I solved this error by changing my yarn shell script, which I had previously changed to bash. Returning it to "sh"

yarn config set script-shell /bin/sh

Or simply reseting it

yarn config delete script-shell

To check which shell script is being used with

yarn config get script-shell
crtormen
  • 191
  • 1
  • 6