Skip to content

fix(compile): resolve bare npm imports in --bundle worker sources#34967

Merged
bartlomieju merged 2 commits into
mainfrom
fix/compile-bundle-npm-snapshot-fallback
Jun 6, 2026
Merged

fix(compile): resolve bare npm imports in --bundle worker sources#34967
bartlomieju merged 2 commits into
mainfrom
fix/compile-bundle-npm-snapshot-fallback

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

deno compile --bundle follows new Worker(new URL(...)) references and
pulls the referenced modules into the bundle graph. When the entrypoint
lives in a subdirectory with its own package scope (for example a dist/
build output with its own package.json) and a worker is authored in a
sibling source tree, a bare npm import from that worker source failed
to resolve with "Import X not a dependency", even though the package is
declared, installed, and resolves fine from the entrypoint's own tree
in the same build. Plain deno bundle was unaffected because it does not
follow those worker references into the source tree.

The package is already present in the build's resolved npm snapshot, so
this falls back to resolving such bare specifiers against that snapshot
by package name, the way Node and Bun locate a package in a reachable
node_modules. The fallback only runs after normal resolution has already
failed, so successful resolutions and plain deno bundle behavior are
unchanged.

Closes #34937

deno compile --bundle follows new Worker(new URL(...)) references and
pulls the referenced source modules into the graph. When the entrypoint
lives in a subdirectory with its own package scope (e.g. a dist/ build
output) and the worker is authored in a sibling source tree, a bare npm
import from that worker source fails to resolve even though the package
is installed and resolves fine elsewhere in the same build, surfacing as
"Import X not a dependency".

Fall back to resolving such bare specifiers against the build's npm
snapshot by package name, matching Node/Bun behavior.

Closes #34937
@bartlomieju bartlomieju modified the milestone: 2.9.0 Jun 6, 2026

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely scoped fix — loosening only after strict graph resolution has already failed is the right shape, and the doc comments + PR description are great. A few things worth addressing before merge, left inline. Main one is version selection when the snapshot holds more than one version of a package; the rest are nits / a test-fidelity check.

Comment thread libs/resolver/graph.rs Outdated
Comment thread libs/resolver/graph.rs
Comment thread cli/tools/bundle/mod.rs
Comment thread tests/specs/compile/bundle/worker_npm_outside_scope/outside/package.json Outdated
@bartlomieju
bartlomieju enabled auto-merge (squash) June 6, 2026 12:09
@bartlomieju
bartlomieju merged commit 591ff87 into main Jun 6, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the fix/compile-bundle-npm-snapshot-fallback branch June 6, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deno compile --bundle reports "Import X not a dependency" where deno bundle succeeds on the same entrypoint

1 participant