{"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":"AnyError","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/run/mod.rs#L309-L345","documentation":"Deno's --watch mode restarts a JavaScript worker on file change, so the entrypoint must be JS/TS. When the main module resolves to an npm package whose `bin` entry is a native compiled executable (detected by is_npm_native_bin in cli/tools/run/mod.rs:327), watching is impossible: Deno cannot re-execute or reload a native binary through the runtime, so it refuses up front instead of silently not reloading.","triggerScenarios":"deno run --watch npm:<package> (or a watch-mode config whose main module is an npm specifier) where the package's `bin` target is a native ELF/Mach-O/PE binary, e.g. platform-specific CLIs shipped via per-OS optionalDependencies like esbuild, @biomejs/biome, or turbo.","commonSituations":"Porting a watch workflow from a local TS entrypoint to an npm CLI; CI scripts that reuse --watch flags mechanically; monorepos where the entry silently changes from a JS shim to a native bin after a package upgrade.","solutions":["Drop --watch and run the package directly: deno run npm:<pkg> or deno x <pkg> — both execute native bins fine.","If you need restart-on-change, wrap it with an external watcher that re-invokes Deno: watchexec -r -- deno x <pkg>.","If the package also ships a JS entry, point the main module at that file (npm:<pkg>/bin/js-entry.js) instead of the native bin."],"exampleFix":"# before\n deno run --watch npm:@biomejs/biome check .\n # error: Cannot use --watch with an npm package whose bin entry is a native executable...\n\n# after — run directly, or let watchexec do the restarting\ndeno x @biomejs/biome check .\n# or: watchexec -r --ext ts,js -- deno x @biomejs/biome check .","handlingStrategy":"validation","validationCode":"# Before adding --watch, check what the package's bin actually is\npkg=node_modules/<pkg>\nbin=$(node -p \"(v => typeof v === 'string' ? v : Object.values(v)[0])(require('./' + process.argv[1] + '/package.json').bin)\" \"$pkg\" 2>/dev/null)\nfile \"$pkg/$bin\" | grep -Eq 'ELF|Mach-O|PE32' && echo 'native bin: do NOT use --watch' || echo 'script: --watch ok'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve --watch for JS/TS entrypoints; native npm CLIs run fine without it.","Check a package's bin target (file(1) output or its package.json) before wiring watch mode.","Drop --watch on CI — one-shot runs gain nothing from it and it cannot work for native bins."],"tags":["npm","watch","binary","run"],"backgroundTag":"watch-mode-unsupported-target","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}