facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 626 forks source link

fix: skip errors that occurred on virtual lines #1226

Open EvanBacon opened 9 months ago

EvanBacon commented 9 months ago

Summary

If you have a module that has import statements generated in the transformer, then it could possibly throw a resolver error on a line that won't exist in the on-disk file. Without this change, the process will throw an unhandled error. Here, we just skip the error improvement step and fallback on the default behavior.

motiz88 commented 9 months ago

Where is the bad source location coming from? This kinda looks like it masks a genuine bug elsewhere. Do you have repro steps? Also, we have tests for this code now, might be worth adding a regression test to cover the fix.

EvanBacon commented 9 months ago

@motiz88 If you have a babel plugin which takes an empty file like "" and injects a bunch of imports:

import "missing"
import "missing2"

Then the resolver will throw an error which breaks the formatter because it attempts to read lines that don't exist on-disk.