ts-node-dev 在进行更改时不重新启动
ts-node-dev not restarting when changes made
这是我的文件:
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
,之后没有更改检测。
问题现已解决。我使用 --debug
发现问题是与 'SIGTERM' 相关的错误。所以我在 npm start
脚本中添加了一个标记 --exit-child
。
我有类似的东西,使用 ts-node-dev 和 pino。
当服务器启动时,有一些日志记录输出服务器初始化进程。当开发服务器由 ts-node-dev 重新启动时,有时它会吐出 write: EPIPE
错误,我假设是重新启动的服务器试图写入旧流。
--exit-child
标志似乎已经解决了这个问题
--exit-child
也为我工作。
package.json
中的示例
"scripts": {
"start": "ts-node-dev --respawn --transpile-only --exit-child --watch src src/index.ts"
},
您可以尝试将 --respawn 和 --inspect 标记放入 package.json
示例:
{
"scripts": {
"start:dev": "tsnd --respawn --inspect --transpile-only --ignore-watch node_modules src/server"
}
}
你可以在你的索引文件中处理它:
这一行:
process.on("SIGTERM", tearDown);
import {$log} from "@tsed/common";
import { PlatformExpress } from "@tsed/platform-express";
import {Server} from "./Server";
async function bootstrap() {
try {
const platform = await PlatformExpress.bootstrap(Server);
await platform.listen();
} catch (error) {
$log.error({event: "SERVER_BOOTSTRAP_ERROR", error});
}
}
const chalk = require("chalk");
process.stdin.resume();
const tearDown = async () => {
process.exit();
};
// // catch ctrl+c event and exit normally
process.on("SIGINT", tearDown);
//catch uncaught exceptions, trace, then exit normally
process.on("uncaughtException", function (e) {
console.log("Uncaught Exception...");
console.log(e.stack);
process.exit(99);
});
// catches "kill pid" (for example: nodemon restart)
process.on("SIGUSR1", tearDown);
process.on("SIGUSR2", tearDown);
process.on("SIGTERM", tearDown);
bootstrap();
这是我的文件:
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
,之后没有更改检测。
问题现已解决。我使用 --debug
发现问题是与 'SIGTERM' 相关的错误。所以我在 npm start
脚本中添加了一个标记 --exit-child
。
我有类似的东西,使用 ts-node-dev 和 pino。
当服务器启动时,有一些日志记录输出服务器初始化进程。当开发服务器由 ts-node-dev 重新启动时,有时它会吐出 write: EPIPE
错误,我假设是重新启动的服务器试图写入旧流。
--exit-child
标志似乎已经解决了这个问题
--exit-child
也为我工作。
package.json
"scripts": {
"start": "ts-node-dev --respawn --transpile-only --exit-child --watch src src/index.ts"
},
您可以尝试将 --respawn 和 --inspect 标记放入 package.json
示例:
{
"scripts": {
"start:dev": "tsnd --respawn --inspect --transpile-only --ignore-watch node_modules src/server"
}
}
你可以在你的索引文件中处理它:
这一行: process.on("SIGTERM", tearDown);
import {$log} from "@tsed/common";
import { PlatformExpress } from "@tsed/platform-express";
import {Server} from "./Server";
async function bootstrap() {
try {
const platform = await PlatformExpress.bootstrap(Server);
await platform.listen();
} catch (error) {
$log.error({event: "SERVER_BOOTSTRAP_ERROR", error});
}
}
const chalk = require("chalk");
process.stdin.resume();
const tearDown = async () => {
process.exit();
};
// // catch ctrl+c event and exit normally
process.on("SIGINT", tearDown);
//catch uncaught exceptions, trace, then exit normally
process.on("uncaughtException", function (e) {
console.log("Uncaught Exception...");
console.log(e.stack);
process.exit(99);
});
// catches "kill pid" (for example: nodemon restart)
process.on("SIGUSR1", tearDown);
process.on("SIGUSR2", tearDown);
process.on("SIGTERM", tearDown);
bootstrap();