8

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?

Nrgyzer
  • 783
  • 1
  • 14
  • 38
  • How about `"nodemon --exec 'yarn run ts-node --cache-directory .tscache' ./src/www.ts"`? – cartant Jul 09 '17 at 09:39
  • 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. – Nrgyzer Jul 09 '17 at 09:44

3 Answers3

9

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

Narendra Solanki
  • 1,042
  • 14
  • 20
5

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"
Scott Willeke
  • 8,884
  • 1
  • 40
  • 52
Nrgyzer
  • 783
  • 1
  • 14
  • 38
1

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

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73