Repository navigation
fix(loader): reject non-JSON modules for JSON imports - #36135
Merged
Merged
Conversation
bartlomieju
pushed a commit
that referenced
this pull request
Jul 23, 2026
## Summary - require modules requested with `type: "json"` to resolve to JSON media - apply the check to prepared modules and direct npm module loading - add a BYONM regression covering a JavaScript package requested as JSON ## Details The loader already rejected JSON modules imported without the JSON attribute, but it did not consistently enforce the reverse direction. In the npm/BYONM path, a non-JSON module requested as JSON could continue through JavaScript loading. This change reports a module-type error before CJS translation or module evaluation when the requested and loaded types do not match. ## Validation - `./tools/format.js` - `cargo check -p deno_resolver --all-features` - `cargo build --bin deno` - `cargo test -p specs_tests --test specs run::byonm_json_attribute_mismatch -- --nocapture` - `cargo test -p specs_tests --test specs run::npm_json_without_attribute_error -- --nocapture` - `cargo test -p specs_tests --test specs run::byonm_exact_version -- --nocapture` - `cargo test -p specs_tests --test specs run::import_attributes_dynamic_import -- --nocapture`
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.
Summary
type: "json"to resolve to JSON mediaDetails
The loader already rejected JSON modules imported without the JSON attribute, but it did not consistently enforce the reverse direction. In the npm/BYONM path, a non-JSON module requested as JSON could continue through JavaScript loading.
This change reports a module-type error before CJS translation or module evaluation when the requested and loaded types do not match.
Validation
./tools/format.jscargo check -p deno_resolver --all-featurescargo build --bin denocargo test -p specs_tests --test specs run::byonm_json_attribute_mismatch -- --nocapturecargo test -p specs_tests --test specs run::npm_json_without_attribute_error -- --nocapturecargo test -p specs_tests --test specs run::byonm_exact_version -- --nocapturecargo test -p specs_tests --test specs run::import_attributes_dynamic_import -- --nocapture