'ts-node' is not recognized as an internal or external command, operating program or batch file

I get an error in my Vs Code terminal and command line that 'ts-node' is not recognized as an internal or external command, operating program or batch file. m is trying to run the launch command in the npm terminal to run dev , and I also added the package.json file.

{
"name": "tsnode",
"version": "1.0.0",
"description": "ts-node experiment.",
"scripts": {
    "dev": "nodemon --exec 'ts-node --cache-directory .tscache' ./server.ts",
    "start": "ts-node --fast ./server.ts"
},
"author": "Mugesh",
"license": "ISC",
"dependencies": {
    "@types/body-parser": "^1.16.3",
    "@types/chalk": "^0.4.31",
    "@types/express": "^4.0.35",
    "@types/node": "^7.0.18",
    "body-parser": "^1.17.1",
    "chalk": "^1.1.3",
    "express": "^4.15.2",
    "nodemon": "^1.11.0",
    "ts-node": "^3.0.4",
    "typescript": "^2.3.4"
}

}

+31
source share
10 answers

I would not recommend relying on a globally installed ts-nodein my own module, as some answers suggest here.

, , , ts-node ( npm install ), , , ts-node , ..

, package.json node_modules.

npx , node_modules.

, , , () ts-node typescript:

rsp@mn-r:~/node/test/ts-test-1$ npm i ts-node typescript
npm WARN ts-test-1@0.0.0 No description
npm WARN ts-test-1@0.0.0 No repository field.

+ ts-node@6.0.3
+ typescript@2.8.3
added 19 packages from 44 contributors in 2.157s
[+] no known vulnerabilities found [19 packages audited]

ts-node:

rsp@mn-r:~/node/test/ts-test-1$ ts-node -v
-bash: /Users/rsp/opt/node/bin/ts-node: No such file or directory

npx:

127!rsp@mn-r:~/node/test/ts-test-1$ npx ts-node -v
ts-node v6.0.3
node v10.1.0
typescript v2.8.3

:

rsp@mn-r:~/node/test/ts-test-1$ ./node_modules/.bin/ts-node -v
ts-node v6.0.3
node v10.1.0
typescript v2.8.3

, .

+29

ts- node

npm install -g ts-node

https://github.com/TypeStrong/ts-node

+26

: Mac OS --exec ts-node , Windows .

- nodemon.json :

{
  "watch": "src/**/*.ts",
  "execMap": {
    "ts": "ts-node"
  }
}

package.json

"scripts": {
  "start": "nodemon src/index.ts"
},
+17

, , .

"dev": "nodemon --exec \"ts-node\" --cache-directory .tscache ./server.ts"

PS 1 . , . .

+8

node_modules , npm i.

+4

ts- , :

1) nodemon → npm nodemon

2) package.json 'scripts' :

"scripts": {
    "start": "nodemon index.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

3) npm start ( , TS)

4) / , , , tsc index.tsc --watch
. , , , , .

+1

Mac, , , .

  1. globaly 'ts-node /usr/local/bin
  2. package.json
  3. /node_modules /usr/local/lib/node_modules/
  4. , , /ts-node/dist chmod +x bin.js
  5. npm ts-node
  6. , dist , .
  7. ts- , , , - .. /
  8. ts-node /usr/local/lib/node_modules/ts-node/node_modules
0

dev . .

0

nodemon:

  • nodemon , ts-node .

:

  • ts-node ( ).
0

Windows, json. (') ("). (") (\"). "package.json":

"dev": "nodemon --exec 'ts-node --cache-directory.tscache'./server.ts",

:
"dev": "nodemon --exec \" ts-node --cache-directory.tscache\"./server.ts",

0

Source: https://habr.com/ru/post/1680129/


All Articles