Skip to content

Fix crash when import error points past the end of the file (#1993) - #1993

Closed
vzaidman wants to merge 1 commit into
react:mainfrom
vzaidman:export-D120317319
Closed

vzaidman wants to merge 1 commit into
react:mainfrom
vzaidman:export-D120317319

Conversation

@vzaidman

@vzaidman vzaidman commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

When Metro cannot find a module being imported, it shows an error with a small preview of your code around that import. Some build tools automatically add imports while transforming your code. Those added imports can point to a line number that does not exist in your saved file. Before this change, Metro crashed while building that preview, which hid the real "Unable to resolve module" error. Now Metro skips lines that do not exist in the file and still shows the real error with a preview of the lines that do exist.

Changes:

  • ModuleResolution.js: skip missing lines when searching for the import location, falling back to the default location.
  • Adds an integration test with a Babel plugin that appends an unresolvable import past the end of the file.

Original contribution from #1226 by evanbacon.

Changelog:
[Fix] Fixed a crash when building the error preview for an unresolvable import pointing past the end of the file (for example, imports added automatically during the build). Metro now skips the missing lines and reports the real "Unable to resolve module" error. (react/metro#1226 by evanbacon)

Reviewed By: cipolleschi

Differential Revision: D120317319

@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 Sep 29, 2026
@meta-codesync

meta-codesync Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@vzaidman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D120317319.

@meta-codesync meta-codesync Bot changed the title Fix crash when import error points past the end of the file Fix crash when import error points past the end of the file (#1993) Sep 29, 2026
vzaidman added a commit to vzaidman/metro that referenced this pull request Sep 29, 2026
Summary:

When Metro cannot find a module being imported, it shows an error with a small preview of your code around that import. Some build tools automatically add imports while transforming your code. Those added imports can point to a line number that does not exist in your saved file. Before this change, Metro crashed while building that preview, which hid the real "Unable to resolve module" error. Now Metro skips lines that do not exist in the file and still shows the real error with a preview of the lines that do exist.

Changes:
- ModuleResolution.js: skip missing lines when searching for the import location, falling back to the default location.
- Adds an integration test with a Babel plugin that appends an unresolvable import past the end of the file.

Original contribution from react#1226 by evanbacon.

Changelog:
[Fix] Fixed a crash when building the error preview for an unresolvable import pointing past the end of the file (for example, imports added automatically during the build). Metro now skips the missing lines and reports the real "Unable to resolve module" error. ([react#1226](react#1226) by [evanbacon](https://github.com/evanbacon))

Reviewed By: cipolleschi

Differential Revision: D120317319
vzaidman added a commit to vzaidman/metro that referenced this pull request Sep 29, 2026
Summary:

When Metro cannot find a module being imported, it shows an error with a small preview of your code around that import. Some build tools automatically add imports while transforming your code. Those added imports can point to a line number that does not exist in your saved file. Before this change, Metro crashed while building that preview, which hid the real "Unable to resolve module" error. Now Metro skips lines that do not exist in the file and still shows the real error with a preview of the lines that do exist.

Changes:
- ModuleResolution.js: skip missing lines when searching for the import location, falling back to the default location.
- Adds an integration test with a Babel plugin that appends an unresolvable import past the end of the file.

Original contribution from react#1226 by evanbacon.

Changelog:
[Fix] Fixed a crash when building the error preview for an unresolvable import pointing past the end of the file (for example, imports added automatically during the build). Metro now skips the missing lines and reports the real "Unable to resolve module" error. ([react#1226](react#1226) by [evanbacon](https://github.com/evanbacon))

Reviewed By: cipolleschi

Differential Revision: D120317319
Summary:
Pull Request resolved: react#1993

When Metro cannot find a module being imported, it shows an error with a small preview of your code around that import. Some build tools automatically add imports while transforming your code. Those added imports can point to a line number that does not exist in your saved file. Before this change, Metro crashed while building that preview, which hid the real "Unable to resolve module" error. Now Metro skips lines that do not exist in the file and still shows the real error with a preview of the lines that do exist.

Changes:
- ModuleResolution.js: skip missing lines when searching for the import location, falling back to the default location.
- Adds an integration test with a Babel plugin that appends an unresolvable import past the end of the file.

Original contribution from react#1226 by evanbacon.

Changelog:
[Fix] Fixed a crash when building the error preview for an unresolvable import pointing past the end of the file (for example, imports added automatically during the build). Metro now skips the missing lines and reports the real "Unable to resolve module" error. ([react#1226](react#1226) by [evanbacon](https://github.com/evanbacon))

Reviewed By: cipolleschi

Differential Revision: D120317319
@robhogan

Copy link
Copy Markdown
Collaborator

Just curious - was something broken about the original PR/import?

@vzaidman

Copy link
Copy Markdown
Contributor Author

Just curious - was something broken about the original PR/import?

Problems with diff train for diffs imported before the diff train. I'm not sure what's the best way to fix it though

@vzaidman

Copy link
Copy Markdown
Contributor Author

@robhogan Ahhh nvm, I just landed the original one DOHHH

@vzaidman vzaidman closed this Sep 29, 2026
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants