fix: support npm: specifiers in --preload and --import#34346
Merged
Conversation
Previously `deno run --preload npm:foo` and `--import npm:foo` failed because the npm package wasn't installed before the preload module was resolved, producing "Could not find constraint" errors. Bare specifiers backed by an import map / package.json entry were also unresolved. Now `preload_modules` accepts the workspace main module resolver (so bare specifiers resolve via the import map), and `create_custom_worker` collects npm package requirements from the main module, preload, and require lists, installing them in a single batch before resolution. Fixes #34303
fibibot
reviewed
May 25, 2026
fibibot
left a comment
Contributor
There was a problem hiding this comment.
preload_modules_with_resolver() now uses the same workspace/npm resolver as the main module, and create_custom_worker() installs package reqs from preload_modules before execute_preload_modules() can load them. The regression spec covers both --import npm:@denotest/say-hello and --preload npm:@denotest/say-hello; no code issue found. Holding approval until CI is green.
fibibot
approved these changes
May 25, 2026
fibibot
left a comment
Contributor
There was a problem hiding this comment.
CI is green now, promoting prior review to APPROVE.
littledivy
pushed a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
`deno run --preload npm:foo` and `deno run --import npm:foo` previously failed with `Could not find constraint 'foo' in the list of packages`, because the npm package referenced by the preload/import flag was never installed before the preload module list was resolved. Bare specifiers that mapped to an npm package via an import map or `package.json` dependency were also unresolved, since the preload pipeline did not run them through the workspace resolver. This change threads the `WorkspaceMainModuleResolver` into `preload_modules_with_resolver` so bare specifiers in `--import` / `--preload` resolve the same way as the main module. It also moves npm package collection inside `CliMainWorkerFactory::create_custom_worker` to gather requirements from the main module, preload list, and require list together, and installs them in one batch before resolution proceeds. Spec test coverage is added in `tests/specs/run/preload_modules_npm` exercising both `--import npm:` and `--preload npm:`. Fixes denoland#34303
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
deno run --preload npm:fooanddeno run --import npm:foopreviouslyfailed with
Could not find constraint 'foo' in the list of packages,because the npm package referenced by the preload/import flag was never
installed before the preload module list was resolved. Bare specifiers
that mapped to an npm package via an import map or
package.jsondependency were also unresolved, since the preload pipeline did not run
them through the workspace resolver.
This change threads the
WorkspaceMainModuleResolverintopreload_modules_with_resolverso bare specifiers in--import/--preloadresolve the same way as the main module. It also moves npmpackage collection inside
CliMainWorkerFactory::create_custom_workerto gather requirements from the main module, preload list, and require
list together, and installs them in one batch before resolution
proceeds.
Spec test coverage is added in
tests/specs/run/preload_modules_npmexercising both
--import npm:and--preload npm:.Fixes #34303