Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn-deduplicate and I are confused about @babel/traverse dependency #1403

Closed
benhandanyan opened this issue Dec 13, 2024 · 4 comments
Closed

Comments

@benhandanyan
Copy link

Do you want to request a feature or report a bug?

Opening the issue to see if it's possible to consolidate dependencies.

I'm trying to understand why the metro-source-map package installs both @babel/traverse and @babel/traverse--for-generate-function-map here.

What is the current behavior?
Some of my teams PRs will have these dependencies combined in yarn.lock, while other PRs will have @babel/traverse--for-generate-function-map separated. Our project utilizes yarn-deduplicate as part of the postinstall process, and we also use Renovate to help automate upgrades.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

My project is using react-native v0.76, babel version is 7.26, node version is 22.12, yarn version is 1.22.19

@benhandanyan
Copy link
Author

This is a screenshot from a pull request generated in my repository by Renovate. It is upgrading an unrelated dependency, and you can see the combining of the babel traverses. In a subsequent PR, I expect to find that they are split again. This has not always been happening, I think it's new since we upgraded react-native to version 0.76

Screenshot 2024-12-13 at 8 33 20 AM

@benhandanyan benhandanyan changed the title yarn-deduplicate is confused about @babel/traverse dependency yarn-deduplicate and I are confused about @babel/traverse dependency Dec 13, 2024
@robhogan
Copy link
Contributor

robhogan commented Dec 13, 2024

I’d recommend using Yarn 1.22.22 - it has a fix relating to lockfiles for aliased dependencies.

https://github.com/yarnpkg/yarn/releases/tag/v1.22.22

As for why Metro has this weird dependency - it’s due to a caching bug in Babel where traversing an AST without going through a transform (as generateFunctionMap does) can populate the Babel traverse (in-memory) cache with nodes missing a hub property, which then fails on a subsequent transform of the same AST. Read more at babel/babel#15752

Installing two separate copies of @babel/traverse keeps their module state separate, so it works around the issue, while still taking advantage of the cache as much as it’s safe to. We made that change in Metro 0.80, #1340.

Let us know if updating Yarn doesn’t fix your issue.

@robhogan
Copy link
Contributor

(I can’t speak for Renovate, but if it’s merging dependencies that are explicitly aliased that sounds like a Renovate bug - maybe they need to update Yarn..)

@benhandanyan
Copy link
Author

benhandanyan commented Dec 13, 2024

Thanks for the reply. I'm going to use the latest yarn version and monitor the repository for a while. Since there's no real problem with metro here, I'll close the issue.

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

No branches or pull requests

2 participants