且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法让 TypeScript 监视我的项目并让 nodemon 重新加载它

更新时间:2023-11-09 18:00:28

nodemon 添加 1000 毫秒的延迟为我解决了这个问题.

Adding a delay of 1000ms to nodemon fixed the issue for me.

https://github.com/remy/nodemon#delaying-restarting

nodemon.json

{
  "watch": ["build"],
  "ext": "js",
  "exec": "npm start",
  "delay": 1000
}

package.json

{
  "name": "demo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node build/index.js",
    "ts": "tsc -w",
    "nodemon": "nodemon",
    "code": "concurrently -n ts,nodemon npm:ts npm:nodemon"
  },
  "devDependencies": {
    "concurrently": "^4.1.0",
    "nodemon": "^1.18.9",
    "typescript": "^3.2.2"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es2017",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "build",
    "baseUrl": ".",
    "paths": {
      "*": [
        "node_modules/*",
        "src/types/*"
      ]
    }
  },
  "include": [
    "src/**/*"
  ]
}

npm 运行代码