【问题标题】:nodemon is unable to find ts-node in exec-parameternodemon 无法在 exec 参数中找到 ts-node
【发布时间】:2017-12-13 04:17:28
【问题描述】:

我正在尝试将 ts-node 与 nodemon 一起使用。两者都是使用 yarn 安装的,我的 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"
  }
}

现在,当我使用“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"
  }

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

【问题讨论】:

  • "nodemon --exec 'yarn run ts-node --cache-directory .tscache' ./src/www.ts" 怎么样?
  • 已经尝试过,但没有成功。使用这个命令我得到了没有找到纱线的消息,尽管纱线是全局安装的并且在所有其他 cli 中都可用。

标签: node.js typescript nodemon yarnpkg ts-node


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      2020 年更新

      我正在尝试使用 nodemon 运行打字稿文件,并且在 package.json 中遵循 dev 脚本就足够了

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

      无需在开发脚本中包含 ts-node。

      我在依赖项中有 ts-node 和 nodemon

      【讨论】:

        猜你喜欢
        • 2019-12-24
        • 2020-02-26
        • 1970-01-01
        • 2020-03-06
        • 2019-06-15
        • 2019-06-08
        • 2020-11-23
        • 2017-04-16
        • 2022-08-02
        相关资源
        最近更新 更多