【问题标题】:Why is nodemon not reacting to changes in my src/ folder?为什么 nodemon 对我的 src/ 文件夹中的更改没有反应?
【发布时间】:2020-08-08 10:42:56
【问题描述】:

当我的src/ 文件夹的子目录中的文件发生更改时,nodemon 不会对其更改做出反应,但会在项目中的其他文件更改时做出反应。

Screenshot of the folder structure

package.json:

    "dev": "nodemon src/server.ts",

nodemon.json: *

{
   "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/server.ts"],
   "exec": "ts-node --project tsconfig.server.json"
}

ts.config.server.json:

    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2017",
        "noEmit": false,
        "outDir": "build/"
    },
    "include": ["src/server.ts"]
}

ts.config.json:

    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "jsx": "preserve",
        "lib": ["dom", "es2017"],
        "baseUrl": ".",
        "moduleResolution": "node",
        "strict": true,
        "allowJs": true,
        "noEmit": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "isolatedModules": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true
    },
    "exclude": ["dist", ".next", "out", "next.config.js"],
    ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

【问题讨论】:

  • 不要在标题中添加标签,它应该读成一个句子。
  • 拜托,如果您可以将所有内容作为文本发布,而不是屏幕截图,例如文件夹结构可以很容易地从tree 命令的输出中复制粘贴。
  • When files inside subdirectories of the src/ are changed, nodemon won't react. 这不是很清楚,你能否把你的问题说得更具体一点。
  • 编辑了您帖子的格式。
  • 谢谢@ruohola,我欠你一杯啤酒

标签: typescript next.js nodemon


【解决方案1】:

你能显示 server.ts 文件吗? 是否更改了 server.ts 中的所有导入路径?

我正在使用带有 gulp 的 nodemon,这工作正常。

gulp.task('serve', function (done) {
  nodemon({
    script: 'server/server.js'
  , ext: 'js html'
  , env: { 'NODE_ENV': 'development' }
  , done: done
  })
})

【讨论】:

    【解决方案2】:

    在 nodemon.json 中尝试更改:

    "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/server.ts"],
    

    到这里:

    "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts"],
    

    【讨论】:

      【解决方案3】:

      @Paolo 的答案似乎对.ts 文件有用! 为.tsx 添加一个虽然没有用。

      最终的解决方案是添加一个带有js json ts tsx 值的ext 字段!

      最终nodemon.json:

          "watch": [".babelrc", "public/locales/**/*.json", "next.config.js", "src/**/*.ts", "src/**/*.tsx"],
          "exec": "ts-node --project tsconfig.server.json",
          "ext": "js json ts tsx"
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-22
        • 2017-05-23
        • 2020-11-23
        • 2016-09-28
        • 2020-08-25
        • 1970-01-01
        • 2017-07-04
        • 2015-06-17
        相关资源
        最近更新 更多