Nodemon -w 保持启动,没有 运行 服务器

Nodemon -w keeps starting, without running the server

当我 运行 nodemon dist/index.js nodemon 运行s 服务器时,但是如果我使用 nodemon -w dist/index.js,它只是一直启动,实际上 运行ning我的服务器。

我从 Typescript 转译了我的 index.js 文件,它看起来像这样:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const App_1 = require("./App");
const port = process.env.PORT || 3000;
App_1.default.listen(port, (err) => {
    if (err) {
        return console.log(err);
    }
    return console.log(`server is listening on ${port}`);
});
//# sourceMappingURL=index.js.map

据我所知,在我使用 tsc -b 命令从打字稿转译后,.js 文件不再更改。

什么会导致 nodemon 一直启动?我该如何解决?

使用 nodemon 最好使用 ts-node。这个库非常适合开发,因为使用 ts-lint 你可以 运行 TypeScript 文件。

nodemon.json ```

{
    "watch": ["server/**/*.ts"],
    "execMap": {
        "ts": "ts-node"
    }
}

```

package.json "dev": "nodemon server/index.ts"