【问题标题】:ts-node-dev not restarting when changes made进行更改时 ts-node-dev 未重新启动
【发布时间】:2020-10-07 13:58:59
【问题描述】:

这是我的文件:

package.json:

"scripts": {
  "generate-interfaces": "ts-node src/cli/generate-interfaces.ts",
  "dist": "npm run generate-interfaces && rm -rf dist && tsc && cp -r static/ dist/ && cp -r resource/ dist/",
  "prestart": "npm run generate-interfaces",
  "start": "ts-node-dev --respawn --transpileOnly --no-notify ./src/index.ts",
  "start:inspect": "ts-node-dev --no-deps --inspect -- ./src/index.ts",
  "pretest": "npm run generate-interfaces",
  "test": "jest"
 }

tsconfig.json

{
"compilerOptions": {
"declaration": true,
"target": "es2017",
"module": "commonjs",
"esModuleInterop": true,
"outDir": "dist",
"sourceMap": true,
"skipLibCheck": true,
"typeRoots": ["node_modules/@types", "./typings", "node_modules/**/*.d.ts"],
"lib": ["esnext"]
},
"include": ["src/**/*.ts", "./typings/**/*.d.ts"],
"exclude": ["node_modules/**", "dist"]
}

当我进行任何更改时,我会收到一个小弹出窗口,但它实际上并没有重新启动服务器,不确定我在这里做错了什么。

注意:我在手动重新启动服务器后第一次进行更改时,它会在终端 [INFO] 22:07:09 Restarting: src/analytics-engine.ts has been modified 中显示一个弹出窗口和类似的内容,之后没有检测到更改。

【问题讨论】:

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


    【解决方案1】:

    问题现已解决。我使用--debug 发现了与“SIGTERM”相关的错误。所以我在npm start 脚本中添加了一个标志--exit-child

    【讨论】:

      【解决方案2】:

      我有类似的东西,使用 ts-node-dev 和 pino。

      当服务器启动时,有一些日志记录到输出服务器初始化进程。当开发服务器通过 ts-node-dev 重新启动时,有时它会吐出 write: EPIPE 错误,我假设是重新启动的服务器试图写入旧流。

      --exit-child 标志似乎已经解决了这个问题

      【讨论】:

        【解决方案3】:

        --exit-child 也为我工作。

        package.json中的示例

        "scripts": {
                "start": "ts-node-dev --respawn --transpile-only --exit-child --watch src src/index.ts"
            },
        

        【讨论】:

          【解决方案4】:

          你可以尝试在你的 package.json 中加入 --respawn--inspect 标志

          例子:

          {
            "scripts": {
              "start:dev": "tsnd --respawn --inspect --transpile-only --ignore-watch node_modules src/server"
            }
          }
          
          

          【讨论】:

            猜你喜欢
            • 2020-09-17
            • 2020-11-04
            • 2021-11-05
            • 1970-01-01
            • 2018-07-08
            • 2020-08-14
            • 2015-09-10
            • 2019-04-18
            • 2020-06-15
            相关资源
            最近更新 更多