ts-node-dev:没有提供可运行的脚本

Ham*_*nce 9 node.js typescript

我的 NodeJs 项目出现错误消息:

dev_api | 纱线运行 v1.15.2
dev_api | 警告 package.json:没有许可证字段
dev_api | $ set debug=* && ts-node-dev --respawn --inspect --transpileOnly ./src/index.ts
dev_api | ts-node-dev:提供的
dev_api 没有可运行的脚本 | 用法:ts-node-dev [选项] 脚本 [参数]
dev_api |
dev_api | 错误 命令失败,退出代码为 1
。信息 请访问https://yarnpkg.com/en/docs/cli/run以获取有关此命令的文档。

我的package.json

{
   "name": "API_CLIENT_BANK",
   "version": "0.0.1",
   "description": "Awesome project developed with TypeORM.",
   "devDependencies": {
      "@types/jest": "^24.0.20",
      "@types/node": "^8.0.29",
      "ts-jest": "^24.1.0",
      "ts-node": "3.3.0",
      "typescript": "3.3.3333"
   },
   "dependencies": {
      "@sentry/node": "5.7.1",
      "@types/bcryptjs": "^2.4.2",
      "@types/body-parser": "^1.17.1",
      "@types/cors": "^2.8.6",
      "@types/helmet": "^0.0.44",
      "@types/jsonwebtoken": "^8.3.5",
      "@types/supertest": "^2.0.8",
      "@types/swagger-jsdoc": "^3.0.2",
      "bcryptjs": "^2.4.3",
      "body-parser": "^1.19.0",
      "class-transformer": "^0.2.3",
      "class-validator": "^0.10.2",
      "cors": "^2.8.5",
      "dotenv": "^8.2.0",
      "express": "^4.15.4",
      "helmet": "^3.21.2",
      "jest": "^24.9.0",
      "jsonwebtoken": "^8.5.1",
      "morgan": "^1.9.1",
      "mysql": "^2.17.1",
      "prettier": "^1.18.2",
      "reflect-metadata": "^0.1.10",
      "sqlite3": "^4.0.3",
      "supertest": "^4.0.2",
      "swagger-jsdoc": "^3.4.0",
      "swagger-stats": "^0.95.11",
      "swagger-ui-express": "^4.1.2",
      "ts-node-dev": "^1.0.0-pre.43",
      "tsc-watch": "^4.1.0",
      "tslint": "^5.20.0",
      "tslint-config-prettier": "^1.18.0",
      "tslint-eslint-rules": "^5.4.0",
      "tslint-plugin-prettier": "^2.0.1",
      "typeorm": "0.2.20"
   },
   "scripts": {
      "tsc": "tsc",
      "start": "set debug=* && ts-node-dev --respawn --inspect --transpileOnly ./src/index.ts",
      "prod": "tsc && node ./build/index.js",
      "schema:drop": "ts-node ./node_modules/typeorm/cli.js schema:drop",
      "schema:sync": "ts-node ./node_modules/typeorm/cli.js schema:sync",
      "migration:run": "ts-node ./node_modules/typeorm/cli.js migration:run",
      "test": "jest --maxWorkers=1 --verbose=true",
      "migration:start": "yarn schema:drop && yarn schema:sync && yarn migration:run"
   }
}
Run Code Online (Sandbox Code Playgroud)

错误说ts-node-dev: no script to runprovided,但我给了它:
set debug=* && ts-node-dev --respawn --inspect --transpileOnly ./src/index.ts

Ian*_*ths 41

如果该错误无法识别选项,则该错误的行为no script to run provided方式稍微无益。ts-node-dev(无论如何,直到 v1.1.6 为止都是如此。)

这里的问题是它不理解该--transpileOnly选项。可能旧版本确实如此,因为您在网络上看到了一些带有该选项的示例。但现在你需要写--transpile-only

您可能认为它会显示类似“无法识别的选项:--transpileOnly”之类的内容,但事实并非如此。

(Emefile Francis Waje 的答案确实包含了这一更改,但很容易被忽略,因为它还提出了另外两个更改:创建ts-node-dev开发依赖项和使用。所以当我第一次阅读该答案时,我完全错过了从到 的npx更改,因为我专注于其他两个更改。所以我在一个单独的答案中调用这个细节,因为它是问题提到的错误的根本原因。)--transpileOnly--transpile-only