Create the plugin. It sets three build options itself:
conditions, so exports resolve as Node's import resolves them:
module-sync where Node supports it, never esbuild's own module;
mainFields: ['main'], as Node ignores a package's module field;
a banner defining require (via createRequire, based on the entry
file), so bundled CommonJS code can require() Node built-ins and
run-time names. A caller's own banner follows it, so it must not start
with #! or declare require.
Node's own --conditions and --preserve-symlinks flags are not applied.
A Node built-in stays an import, with the node: prefix (so a subpath
such as readline/promises is never handed to esbuild's resolver).
An import (static, or a literal dynamic import()) of a bare package
specifier stays an import when it resolves to an ES module of that very
package (the nearest named package.json above the file has the
specifier's package name). It is written as the resolved file's absolute
file: URL, so Node loads the package itself (one instance, shared with
the host), resolved from the importing file rather than from wherever the
compiled output is written. Linked packages (npm link, workspaces)
count: the name decides, not the path. A package installed under an
alias ("zod3": "npm:zod@^3"), or whose file sits under a nested
package.json with another name, is bundled instead (its own copy).
Everything else is bundled, as before: the entry, relative imports (also
inside a config shipped in node_modules), tsconfig path aliases,
TypeScript and JSON files, CommonJS packages (bundling keeps esbuild's
interop, e.g. a __esModule default export) and require() calls (an
ESM bundle can't require a URL).
Create the plugin. It sets three build options itself:
conditions, soexportsresolve as Node'simportresolves them:module-syncwhere Node supports it, never esbuild's ownmodule;mainFields: ['main'], as Node ignores a package'smodulefield;bannerdefiningrequire(viacreateRequire, based on the entry file), so bundled CommonJS code canrequire()Node built-ins and run-time names. A caller's own banner follows it, so it must not start with#!or declarerequire.Node's own
--conditionsand--preserve-symlinksflags are not applied.node:prefix (so a subpath such asreadline/promisesis never handed to esbuild's resolver).import(static, or a literal dynamicimport()) of a bare package specifier stays an import when it resolves to an ES module of that very package (the nearest namedpackage.jsonabove the file has the specifier's package name). It is written as the resolved file's absolutefile:URL, so Node loads the package itself (one instance, shared with the host), resolved from the importing file rather than from wherever the compiled output is written. Linked packages (npm link, workspaces) count: the name decides, not the path. A package installed under an alias ("zod3": "npm:zod@^3"), or whose file sits under a nestedpackage.jsonwith another name, is bundled instead (its own copy).node_modules),tsconfigpath aliases, TypeScript and JSON files, CommonJS packages (bundling keeps esbuild's interop, e.g. a__esModuledefault export) andrequire()calls (an ESM bundle can'trequirea URL).