【问题标题】:Nodemon not restarting on file changeNodemon 没有在文件更改时重新启动
【发布时间】:2022-01-22 00:54:15
【问题描述】:
  "scripts": {
    "start": "npm run prod",
    "build": "npm-run-all clean transpile",
    "server": "node ./dist/bin/www",
    "dev": "npm run lint && NODE_ENV=development nodemon --inspect=notifications:9236 --exec babel-node bin/www",
    "prod": "NODE_ENV=production npm-run-all build server",
    "transpile": "babel ./ --out-dir dist",
    "lint": "eslint '*.js' ",
    "lint:watch": "watch 'npm run lint' ",
    "precommit": "npm run lint",
    "prepush": "npm run lint",
    "clean": "rimraf dist",
    "test": "jest"
  }

我在 docker 上有多个微服务,每个微服务的 package.json 中都包含类似的脚本。 每当我进行更改并保存文件时,nodemon 都不会检测到更改并重新启动服务器。

当微服务启动时,Nodemon 确实会启动,输出以下内容:

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): **/* public/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node --inspect=notifications:9236 bin/www`

我不得不提一下,这是一个基于 Mac OS 构建的项目,我目前正在 Windows 上运行它,如果它有任何相关性的话。

【问题讨论】:

    标签: node.js docker nodemon


    【解决方案1】:

    这在windows上是相关的,因为运行unix的容器中的文件系统差异Duplicate question

    如果您设置 nodemon.json 来轮询更改,它应该会更新,但它在内存方面非常昂贵

    {
     "verbose": true,
     "watch": ["src/**/*.ts"],
     "exec": "ts-node ./src/index.ts",
     "pollingInterval": 100,
     "legacyWatch": true
    }
    

    【讨论】:

    • 添加 legacyWatch 成功了。我之前在其他问题中看到过这一点,但我没有意识到我们在 package.json 中使用 nodemon 的配置而不是不同的 json。您编写了更完整的配置这一事实帮助我在我们的项目中找到了它。谢谢。 :)
    【解决方案2】:

    在您尝试运行的任何启动脚本中,您都需要包含nodemon

    例如:

    "start": "nodemon run prod"
    

    【讨论】:

    • 我已将其调整为以下内容:“scripts”:{“start”:“nodemon run prod”,“build”:“npm-run-all clean transpile”等...}还是不行。
    • 但是您是否将npm 替换为nodemon 用于build 以及所有其他的?
    【解决方案3】:

    也许已经是这样了,但是你有你的代码文件夹作为一个卷吗?因为如果您不使用卷与 dockerized 文件共享本地更改,它不会更新,因为文件将保持不变

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 2019-03-23
      • 2017-08-13
      • 1970-01-01
      • 2014-09-24
      • 2020-06-15
      • 2018-10-04
      • 2016-10-10
      相关资源
      最近更新 更多