Skip to content

Resolver: Don't resolve directories as assets - #2055

Open
robhogan wants to merge 1 commit into
mainfrom
pr2055
Open

robhogan wants to merge 1 commit into
mainfrom
pr2055

Conversation

@robhogan

@robhogan robhogan commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

A package or directory whose name ends in one of resolver.assetExts can't be imported, because the resolver treats it as an asset file. require('lodash.zip') (a real package) fails with:

Failed to get the SHA-1 for: /path/to/project/node_modules/lodash.zip.

Any asset extension causes this, and it also breaks relative imports of directories ending in an extension, eg require('./icons.png') where icons.png is a directory containing an index.js.

This change only accepts asset candidates that are files (type === 'f'), so directories fall through to package resolution as they would for any other name.

Fixes: #441

Changelog:

 - **[Fix]**: Resolver: packages and directories named with an asset extension (e.g. `lodash.zip`) resolve as modules rather than failing as assets

Test plan:
New tests in resolver-test.js for a package (lodash.zip) and a relative directory (icons.png), both failing before this change (resolving to the directory itself) and passing after.

Also checked end-to-end by patching published metro@0.87.1: require('lodash.zip') builds, and a real ./assets/pic.png still resolves as an asset.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 11, 2026
@robhogan
robhogan requested a balanced review from Copilot October 11, 2026 09:40

Copilot AI 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.

馃煝 Approval recommended

The fix is narrowly scoped, correct, and covered by relevant regression tests.

0 open findings

What changed in this PR

Prevents directories with asset-like extensions from being incorrectly resolved as assets.

Changes:

  • Restricts asset candidates to files.
  • Adds package and relative-directory regression tests.
File Description
createModuleResolver.js Filters non-file asset candidates.
resolver-test.js Tests asset-extension directory resolution.

馃 Review effort: Balanced


馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 11, 2026
@meta-codesync

meta-codesync Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D124673317.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bundling failed: ReferenceError: SHA-1 for file .../node_modules/lodash.zip is not computed

2 participants