Comments (18)
jest-haste-map 20.0.5 appears to be working fine in several of our projects including a test suite.
from metro.
I think Haste modules are always preferred, but it's possible it is a problem in jest-haste-map
that make it not detect the existence of the merge
Haste module as expected in particular conditions. The resolution logic wasn't changed so I'm surprised it appears to be a recent regression. We did add some bug fixes to jest-haste-map
, possibly one could have caused a regression.
from metro.
So another few hours of debugging, and I found that resetting the cache fixes things. Posted a follow-up with my analysis of why various voodoo magic fixes worked: facebook/react-native#13765 (comment)
No idea what led to a corrupted cache in the first place. I have my old "busted" cache, if you are interested still.
The relevant merge bit, which explains why it was skipping the haste resolution and falling back on node module resolution:
"mergeInto":{"g":["/fullpath/mobile/node_modules/react-native/Libraries/vendor/core/mergeInto.js",0]},
"mergeHelpers":{"g":["/fullpath/mobile/node_modules/react-native/Libraries/vendor/core/mergeHelpers.js",0]},
"merge":{}
And the "duplicates"
property, which included:
"merge":{"g":{
"/fullpath/mobile/node_modules/react-native/node_modules/merge/package.json":1,
"/fullpath/mobile/node_modules/react-native/Libraries/vendor/core/merge.js":0
}}
from metro.
Ohhh! This is very useful, thank you. Unfortunately, I expect thing to get broken again. This is actually a legitimate problem, and it needs to generate an error more proeminently. The duplication of modules stored in the duplicates
field is real. I think there are 2 action items from there:
- we need to make the
HasteMap#getModule
function crash immediately if there is module duplication for the requested module name. Right now, it's silent, so callsites believe the module is just not there. This is incorrect. - we may want to ignore "haste packages" contained inside
node_modules
, and/or the duplication detection system should keep packages and modules separate, that it doesn't look like to do right now.
from metro.
Glad to hear it helped!
FWIW, I believe this duplicate module merge
comes directly from react-native->sane->exec-sh->merge
dependency, so is unrelated to anything I've imported. So you fixing # 1 alone would probably break RN.
Unfortunately, judging from the bug that led me here, I'm not sure anyone on the RN side is aware of this duplicate module issue yet.
from metro.
we may want to ignore "haste packages" contained inside
node_modules
Last time I looked into this for RN 0.45, I think I arrived at a similar conclusion. In RN, providesModuleNodeModules
whitelists only react-native
now, but IIRC the whitelist includes <project>/node_modules/react-native/**
, which includes <project>/node_modules/react-native/node_modules/**
. I think it'd be enough to tell jest-haste-map to ignore the node_modules
subdirectory under the whitelisted modules.
from metro.
In my case, I believe merge
was adjacent to react-native
in my top-level node_modules
, not within react-native/node_modules/
.
Not sure if I was doing something wrong to achieve that end-result? In case it's relevant, I was building react-native myself, and then npm install ../path-to/react-native
into my mobile app's node_modules/
.
from metro.
Could you perhaps have had multiple copies of merge
under <proj>/node_modules/react-native/
?
from metro.
That's what it looks like from the last JSON snippet you posted:
"merge":{"g":{
"/fullpath/mobile/node_modules/react-native/node_modules/merge/package.json":1,
"/fullpath/mobile/node_modules/react-native/Libraries/vendor/core/merge.js":0
}}
I think if we filter out node_modules/react-native/node_modules
we'd go down to just node_modules/react-native/Libraries/vendor/core/merge.js
as desired.
from metro.
Ahhhh really?! Thanks for double-checking my assumptions! I was speaking on what exists in my directory now...which I mistakenly assumed was what existed back when things were broken. :(
Man, talk about a merge
conflict...hah!
So perhaps my "fix" was to have removed react-native/node_modules/merge/
, but I needed to rebuild the watchman cache for anything to have noticed that and start working again. And I mistakenly assumed it was rebuilding the cache that made things work for me?
(going to update my "fix instructions" comment facebook/react-native#13765 in the react-native issue to reflect this)
from metro.
I make a change to jest-haste-map
that will make it throw if duplicate modules are found: jestjs/jest#3976. This doesn't fix this problem of duplicated merge
modules, but this will make it much more explicit what's going on, that I think it's the correct approach. The merge
module that is in node_modules
will have to be blacklisted from jest-haste-map
.
from metro.
@jeanlauliac I think this PR might fix things (filters out nested node_modules). Could you take a look at it? jestjs/jest#3984
from metro.
The jest-haste-map PR landed (thank you @jeanlauliac!) so sometime in the future when it gets published to npm we'll be able to use it in Metro (and indirectly, RN). Fingers crossed that the duplicate module collisions are gone forever unless there are actually duplicates within a package's own code.
from metro.
Do you think we should we release a new minor/rev version off the last major to fix the issues people have right now?
from metro.
@jeanlauliac That's a nice idea, why don't we try it if it's not too much trouble to publish jest-haste-map to npm? RN 0.46 uses a version of Metro that uses jest-haste-map ^20.0.1 so people should automatically be able to get minor & patch updates. (Perhaps we should first set the latest
npm dist-tag to an older version so that people only get the new jest-haste-map if they explicitly install it, so people like me and mikelambert can test it out.)
from metro.
There is an [email protected]
on npm if you want to test some stuff out?
from metro.
I released 20.0.5
with jestjs/jest#3984, do you want to try that out, make sure everything is in order? I kept the latest
tag on 20.0.4
, but I think this won't prevent people from getting the new version if they have the ^20.0.1
specifier. Since tests pass, and that we've been having the beta
/chi
versions internally for some days, I trust this shouldn't cause problems. At worst we can rollback and release 20.0.6
.
from metro.
Looks like we're good to close. Feel free to reopen if you still observe problems!
from metro.
Related Issues (20)
- Unable to resolve self-referring "subpath exports" from within a haste module HOT 1
- `nodeModulesPaths` not working as expected with React Native HOT 1
- Cannot read property 'transformFile' of undefined HOT 1
- Including local packages from outside project root. Can we do better?
- [BUG] Terser mangler issue after upgrading to RN 0.74.5
- Problem during ReactNative project deployment for iOS HOT 2
- Add types for `require.context` HOT 1
- Package Exports resolution differs from Node in 2 edge cases HOT 3
- Slow bundle download(~2 mins) in dev mode by ReloadCommand(r) on iOS after RN 72 upgrade HOT 6
- Uncaught TypeError: (0 , import_toolkit.createSlice) is not a function
- [Help Wanted] Need help with the blocklist option to exclude a folder from metro build
- Metro bundle not connecting with iOS simulator in Release and Debug mode
- Metro bundle not connecting to iOS simulator in Release and Debug mode HOT 5
- Metro has encountered an error HOT 3
- Validation Warning: Unknown option... This is probably a typing mistake. Fixing it will remove this message.
- error index.js: Cannot read properties of undefined (reading 'match')
- Load raw files as text and watch for changes
- Why is the "getModules" function only available in DEV mode? HOT 7
- "server.runInspectorProxy" warning after update to version "0.73.6" #233 HOT 3
- `require()` errors not propagated upwards to calling function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metro.