# Traced externals

A package in `build.external`, and any package that holds a `.node` file (a native add-on, which a bundle cannot contain), stays a bare `import` in the server bundle. On `bun`, `node`, the node host aliases and every other node-target preset, `hamur build` copies each of them into `.output/server/node_modules/` with its `dependencies` and `optionalDependencies`, resolved the way Node does from the package's own folder; a missing optional dependency is skipped. Of a package it copies only what `files` and `exports` name (and every `.node` file) when it has either, else the whole folder; a nested `node_modules` and a link that points out of the package are never followed. `.output/server/package.json` lists the traced packages as `{ "type": "module", "dependencies": { … } }`, so `npm install` in a copied tree restores what a copy lost. `build.traceInclude` adds globs of extra files.

A package whose `.node` file is loaded by a dynamic `require` (as `bindings` does) is not seen by the build: name it in `build.external`. A browser-target preset such as `cloudflare` has no `node_modules`, so an external that is not a `node:` or `cloudflare:` module fails: `build.external "pg-native" cannot run on the cloudflare preset: it has no node_modules`.
