Skip to content

fix: support npm: specifiers in --preload and --import#34346

Merged
bartlomieju merged 1 commit into
mainfrom
fix/preload-npm-specifier
May 26, 2026
Merged

fix: support npm: specifiers in --preload and --import#34346
bartlomieju merged 1 commit into
mainfrom
fix/preload-npm-specifier

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

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 #34303

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 fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI is green now, promoting prior review to APPROVE.

@bartlomieju bartlomieju changed the title fix(cli): support npm: specifiers in --preload and --import fix: support npm: specifiers in --preload and --import May 26, 2026
@bartlomieju
bartlomieju merged commit f542a81 into main May 26, 2026
269 of 271 checks passed
@bartlomieju
bartlomieju deleted the fix/preload-npm-specifier branch May 26, 2026 08:00
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
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.

customisation api not working with loader on npm package

2 participants