Cannot find documentation for metro.config.js > resolver > resolveRequest
See original GitHub issueI cannot find any docs for the resolveRequest function listed at https://facebook.github.io/metro/docs/configuration#resolverequest
I implemented the function and inspected it with console.log(arguments)
, but when I return a string, it throws a type error.
resolveRequest(context, module, platform){
let res = require.resolve(path.resolve(context.originModulePath, module));
console.log(res);
return res;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Configuring Metro - Meta Open Source
A Metro config can be created in these three ways (ordered by priority):. metro.config.js; metro.config.json; The metro field in package.json.
Read more >How can I configure metro to resolve modules outside of my ...
2) Check `blockList` in your metro. config. js and make sure it isn't excluding the file path. The potential causes do not apply...
Read more >@rnx-kit/metro-resolver-symlinks - npm
Start using @rnx-kit/metro-resolver-symlinks in your project by running `npm i ... resolveRequest in your metro.config.js :.
Read more >@lomray/metro-custom-path-resolver - npm package | Snyk
Ensure you're using the healthiest npm packages. Snyk scans all the packages in your projects for vulnerabilities and provides automated fix advice. Get...
Read more >How to import files from outside of root directory with React ...
...code, metro.config.js, rn-cli.config.js, etc. ... But this doesn't work. ... https://facebook.github.io/metro/docs/en/configuration#resolver-options.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah I see - if you
init
a new React Native app today you’ll getreact-native@0.67.2
(latest stable) which includesmetro@0.66.2
, so the metro docs prior to 0.68 apply. Unfortunately, we don’t yet have a versioned docs website for metro, but you can access the raw docs at that point from github - https://github.com/facebook/metro/tree/v0.66.2/docs.Prior to metro 0.68,
context.resolveRequest
points directly back to your own custom resolver, rather than the default resolver - so calling it from your own resolver creates a recursive loop which eventually throws, gets caught internally and manifests as a failed resolution. To access the default resolver you do need to usemetro-resolver
and ensure that you unsetresolveRequest
when passing the context, so the last thing you try is almost correct. The critical difference is that, in <0.68, the resolver takes a fourth argument, “realModuleName
”.So in summary, these are equivalent:
For Metro >=0.68
For Metro < 0.68
Hope that helps, and sorry for the docs confusion.
There isn’t any useful docs for how to use the resolveRequest prop for module aliasing, so I played around with it and this is what I came up with: