nodemon is unable to find ts-node in exec-parameter
Asked Answered
R

3

9

I'm trying to use ts-node with nodemon. Both are installed using yarn and my package.json has the following structure:

{
  "name": "yarnTest",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@types/express": "^4.0.36",
    "bootstrap-sass": "^3.3.7",
    "nodemon": "^1.11.0",
    "typescript": "^2.4.1"
  },
  "dependencies": {
    "@types/chalk": "^0.4.31",
    "chalk": "^2.0.1",
    "express": "^4.15.3",
    "ts-node": "^3.2.0"
  },
  "scripts": {
    "dev": "nodemon --exec 'ts-node --cache-directory .tscache' ./src/www.ts",
    "start": "ts-node --fast ./dist/www.ts"
  }
}

Now, when I use "yarn run dev", it executes nodemon and nodemon tries to execute "ts-node" but nodemon tells me that the command "ts-node" does not exist:

Der Befehl "'ts-node" ist entweder falsch geschrieben oder konnte nicht gefunden werden.

Yarn is installed globally but ts-node is installed for my project only. I already tried:

  "scripts": {
    "dev": "nodemon --exec 'yarn run ts-node --cache-directory .tscache' ./src/www.ts",
    "start": "ts-node --fast ./dist/www.ts"
  }

But this gives me the error that "yarn" is not found :( Any ideas how to fix this issue?

Rubin answered 9/7, 2017 at 9:32 Comment(2)
How about "nodemon --exec 'yarn run ts-node --cache-directory .tscache' ./src/www.ts"?Priscian
Already tried without success. Using this command I'm getting the message that yarn is not found, although yarn is installed globally and available in all other cli's.Rubin
R
7

I finally solved the issue! After some hours I figured out that nodemon told me, that it's unable to find "'ts-node" (or "'yarn"). The apostroph was confusing me, so I finally replaced both apostrophes in my package.json with " and now my working script command is the following one:

 "dev": "nodemon --exec \"ts-node --cache-directory .tscache\" ./src/www.ts"
Rubin answered 9/7, 2017 at 12:36 Comment(0)
G
13

You should install ts-node first, run npm install -g ts-node

Galleon answered 2/5, 2021 at 6:32 Comment(0)
R
7

I finally solved the issue! After some hours I figured out that nodemon told me, that it's unable to find "'ts-node" (or "'yarn"). The apostroph was confusing me, so I finally replaced both apostrophes in my package.json with " and now my working script command is the following one:

 "dev": "nodemon --exec \"ts-node --cache-directory .tscache\" ./src/www.ts"
Rubin answered 9/7, 2017 at 12:36 Comment(0)
A
2

2020 Update

I am trying to run a typescript file with nodemon and following dev script in package.json is sufficient

{
    "dev": "nodemon src/index.ts"
}

No need of including ts-node in the dev script.

I have ts-node and nodemon in dependencies

Archival answered 27/5, 2020 at 3:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.