Skip to content

fix(npm): tolerate malformed scripts field in packuments - #36324

Merged
bartlomieju merged 1 commit into
mainfrom
fix/npm-malformed-scripts-36323
Jul 29, 2026
Merged

fix(npm): tolerate malformed scripts field in packuments#36324
bartlomieju merged 1 commit into
mainfrom
fix/npm-malformed-scripts-36323

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Installing or inspecting some packages that historically shipped a malformed
package.json fails on 2.9.x. For example deno info npm:jsox errors with:

error: Failed loading https://registry.npmjs.org/jsox for package "jsox"
Caused by: invalid type: string "", expected a map at line 1 column 2

The cause is in the slim-packument caching path. When building the cached
packument, has_install_script deserializes each version's scripts field
into a BTreeMap<String, &RawValue> and propagates any error. The version
jsox@1.1.121 has "scripts": "" (an empty string rather than an object),
so the parse fails and the error bubbles all the way up, aborting the load of
the entire packument.

This treats a scripts field that doesn't deserialize into an object as
having no lifecycle scripts, matching how the rest of the registry parsing
already tolerates malformed historical fields, instead of failing the whole
load.

Verified that deno info npm:jsox now succeeds against a clean cache, and
added a unit test covering non-object scripts values.

Closes #36323

@deno-cla-assistant

deno-cla-assistant Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deno Individual Contributor License Agreement

All contributors have signed the CLA. Thank you!

Re-run CLA check


This is an automated message from CLA Assistant

Some historical packuments contain a `scripts` field that is not a map
(e.g. npm:jsox@1.1.121 has `"scripts":""`). `has_install_script` parsed
it as a `BTreeMap` and propagated the error, which aborted the entire
packument load with:

  invalid type: string "", expected a map at line 1 column 2

Treat a `scripts` field that doesn't deserialize into an object as having
no lifecycle scripts instead of failing the load.

Closes #36323
@bartlomieju
bartlomieju force-pushed the fix/npm-malformed-scripts-36323 branch from 4126f46 to dab03e1 Compare July 27, 2026 08:38
@bartlomieju
bartlomieju merged commit 1715647 into main Jul 29, 2026
268 of 270 checks passed
@bartlomieju
bartlomieju deleted the fix/npm-malformed-scripts-36323 branch July 29, 2026 09:02
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.

Package versions parsing fails when it historically contained a malformed package.json

1 participant