4

I am following the example as it is described here:

https://bilalbudhani.com/chokidar-esbuild/

When I do:

node esbuild.config.js --watch

I get the message:

[ERROR] Invalid option in build() call: "watch"

I have no idea why this is happening.

Is "watch" not longer a parameter?

I also did this example:

const path = require('path')

require("esbuild").build({
  entryPoints: ["application.js", "client.js"],
  bundle: true,
  sourcemap: true,
  outdir: path.join(process.cwd(), "app/assets/builds"),
  absWorkingDir: path.join(process.cwd(), "app/javascript"),
  minify: true,
  watch: true,
})
.then(() => console.log("⚡Done"))
.catch(() => process.exit(1));

If i remove the line "watch:true", it compiles ok. But if I leave it, I get the same error:

Invalid option in build() call: "watch"

when I do: node esbuild.config.js

Thank you in advance

Nick_K
  • 541
  • 6
  • 22
  • 1
    Which esbuild version you're using? v0.17 change quite a bit recently and docs are not up to date yet. Try with latest v0.16 – Fabian Jan 25 '23 at 08:43
  • 1
    You might be interested that esbuild now supports `serve` combined with `watch`. See https://github.com/evanw/esbuild/blob/main/CHANGELOG.md#0170 – Fabian Jan 25 '23 at 10:38
  • @Fabian I get now. From 0.17.4 docs: "..This change removes the incremental and watch options as well as the serve() method, and introduces a new context() method...". I used esbuild 0.17.4. Downgraded to 0.16.17 and it worked! Thank you. I use rails with esbuild and started with this config: https://github.com/rails/jsbundling-rails/issues/8#issuecomment-962138249. Anyway, you should have replied instead of commenting so I could accept you answer. Thank you again. – Nick_K Jan 25 '23 at 12:07
  • By the way, I have no idea how the esbuild.config.js should work with 0.17.4 new async api. – Nick_K Jan 25 '23 at 13:08
  • 1
    Someone was kind enough to provide a solution to this problem with esbuild 0.17x. See here: https://github.com/rails/jsbundling-rails/issues/8#issuecomment-1403699565 – Nick_K Jan 26 '23 at 09:02

1 Answers1

7

Summing up from the comments:

esbuild <v0.16 has removed the watch option. Most tutorials and HowTos are pointing to that version. Downgrade your esbuild to that if you want to use it like described there.

Better option is to use esbuild >0.16 which has a built in live reload which combines watch and serve using the newly introduced context

Fabian
  • 546
  • 5
  • 14