nodemon 无法在 exec 参数中找到 ts-node

Nrg*_*zer 3 node.js typescript nodemon yarnpkg ts-node

我正在尝试将 ts-node 与 nodemon 一起使用。两者都使用纱线安装,我的 package.json 具有以下结构:

{
  "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"
  }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我使用“yarn run dev”时,它执行 nodemon 并且 nodemon 尝试执行“ts-node”但 nodemon 告诉我命令“ts-node”不存在:

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

Yarn 是全局安装的,但 ts-node 仅为我的项目安装。我已经尝试过:

  "scripts": {
    "dev": "nodemon --exec 'yarn run ts-node --cache-directory .tscache' ./src/www.ts",
    "start": "ts-node --fast ./dist/www.ts"
  }
Run Code Online (Sandbox Code Playgroud)

但这给了我找不到“纱线”的错误:(任何想法如何解决这个问题?

Nar*_*nki 11

你应该先安装ts-node,运行npm install -g ts-node


Nrg*_*zer 5

我终于解决了这个问题!几个小时后,我发现 nodemon 告诉我,它无法找到“'ts-node”(或“'yarn”)。撇号让我很困惑,所以我最终用 " 替换了 package.json 中的两个撇号,现在我的工作脚本命令如下:

 "dev": "nodemon --exec \"ts-node --cache-directory .tscache\" ./src/www.ts"
Run Code Online (Sandbox Code Playgroud)