【问题标题】:Nodemon not reloading. What's wrong with this nodemon.json fileNodemon 没有重新加载。这个 nodemon.json 文件有什么问题
【发布时间】:2017-10-03 20:45:02
【问题描述】:

这是我的 nodemon.json

{ 
    "watch": ["src/**/*.ts"],
    "exec": "node out/index.js" 
}

我通过执行来运行nodemon:

nodemon

在 nodejs 根目录中

这是输出:

 % nodemon                                                                                                     
[nodemon] 1.11.0                                                                                
[nodemon] to restart at any time, enter `rs`                                                                                                                       
[nodemon] watching: src/**/*.ts                                                                                                                       
[nodemon] starting node out/index.js
Yay! Started app!

但是当我在 src 中编辑任何 ts 文件时,nodemon 不会重新启动应用程序。

更新

运行nodemon --watch src/index.ts --exec 'node out/index.js'

在修改 index.ts 时运行并重新加载应用程序

但是,使用通配符运行

nodemon --watch 'src/**/*.ts' --exec 'node out/index.js'

nodemon --watch src --exec 'node out/index.js'

不重新加载应用程序。

【问题讨论】:

  • 您将需要一个ts-node 包。参考:stackoverflow.com/questions/37979489/…
  • 我从您提供的链接开始,但它对我不起作用,因此我开始简化脚本并最终以那个链接结束。但它也不起作用

标签: node.js typescript nodemon


【解决方案1】:

解决了!

通过在详细模式下运行 nodemon,我发现默认情况下它只观看 *.js 文件,不管您正在观看什么通配符。因此在命令中添加-e ts 可以解决问题:

nodemon --watch src/ --exec 'node out/index.js' -e ts

如果有人使用nodemon.json,这是我修复后的:

{ 
    "watch": ["src"],
    "exec": "tsc && node out/index.js" ,
    "ext": "js, json, ts, proto"
}

【讨论】:

  • 如果您正在执行node out/index.js,那么在out 目录中查看js 文件会更有意义
  • nodemon.json { "watch": ["src/*", "package.json"], "ext": "ts js json" } 在 package.json { "scripts": { "start": "nodemon -r source-map-support/register 。" }, } 当使用yarn start 运行时,你会得到$ nodemon -r source-map-support/register . [nodemon] 2.0.7 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): src/**/* lb3app/server/**/* package.json [nodemon] watching extensions: ts,js,json [nodemon] starting node -r source-map-support/register . Server is running at http://127.0.0.1::3000
【解决方案2】:

在 package.json 脚本中使用 single quotation 表示多值参数,例如 `--exec'。

例如我将"nodemon --exec npm run build-langs" 更改为"nodemon --exec 'npm run build-langs'" 并工作。

【讨论】:

    猜你喜欢
    • 2019-09-13
    • 2013-02-24
    • 2020-02-08
    • 2021-08-10
    • 2013-02-17
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多