{"record":{"id":"fb0d75546477ac19","repo":"denoland/deno","slug":"cannot-use-watch-with-an-npm-package-whose-bin-e","errorCode":null,"errorMessage":"Cannot use --watch with an npm package whose bin entry is a native executable: {main_module}","messagePattern":"Cannot use --watch with an npm package whose bin entry is a native executable: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"cli/tools/run/mod.rs","lineNumber":327,"sourceCode":"      watcher_communicator.show_path_changed(changed_paths.clone());\n      Ok(async move {\n        let factory = CliFactory::from_flags_for_watcher(\n          flags,\n          watcher_communicator.clone(),\n        );\n        let cli_options = factory.cli_options()?;\n        let main_module = cli_options.resolve_main_module()?;\n        let preload_modules = cli_options.preload_modules()?;\n        let require_modules = cli_options.require_modules()?;\n\n        if main_module.scheme() == \"npm\" {\n          set_npm_user_agent();\n        }\n\n        maybe_npm_install(&factory).await?;\n\n        if is_npm_native_bin(&factory, main_module).await? {\n          return Err(deno_core::anyhow::anyhow!(\n            \"Cannot use --watch with an npm package whose bin entry is a native executable: {main_module}\"\n          ));\n        }\n\n        let _ = watcher_communicator.watch_paths(cli_options.watch_paths());\n\n        let mut worker = factory\n          .create_cli_main_worker_factory()\n          .await?\n          .create_main_worker(\n            mode,\n            main_module.clone(),\n            preload_modules,\n            require_modules,\n          )\n          .await?;\n\n        let exit_code = if watch_flags.hmr {","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/tools/run/mod.rs#L309-L345","documentation":"`deno run --watch` restarts the program when watched files change, which requires a JavaScript entry point. When the main module is an `npm:` package, Deno resolves its bin entry and reads the first bytes (`is_native_binary` checking ELF/PE/Mach-O magic); a compiled executable cannot be reloaded on change, so the --watch combination is rejected up front.","triggerScenarios":"`deno run --watch npm:<package>` where the package's bin entry is a native binary (e.g. esbuild or other Rust/Go-distributed CLIs) instead of a JS shim.","commonSituations":"Wrapping native CLIs in a deno watch loop during development; porting npm-exec-watch-style workflows to Deno.","solutions":["Drop --watch for native-bin npm packages: run `deno run npm:<pkg> ...` once per invocation","Pair an external file watcher (watchexec, fswatch, watch) with the deno command instead","Switch to a JS-implemented equivalent package if you truly need reload-on-change"],"exampleFix":"# before\ndeno run --watch npm:esbuild --bundle src/main.ts\n# after — run without watch, or wrap with an external watcher\ndeno run npm:esbuild --bundle src/main.ts\nwatchexec -e ts -- deno run npm:esbuild --bundle src/main.ts","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check whether an npm package's bin is a compiled binary before wiring it into --watch","Use an external watcher (watchexec, fswatch) for native-tool rebuild loops","Reserve `deno run --watch` for JS/TS entry points"],"tags":["run","watch","npm","native-binary","cli"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}