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
Metro neglects to check ".native.js" before ".js" when "main" ends with ".js" already #485
Comments
hi, are there any workarounds to the problem? it still exists in 0.63 |
Got hit by this today. Do we have the related code where to apply the fix? Would love to give it a try |
I'm not certain whether this is a bug or is intended behaviour (in the context of package entry points) in order to respect the exact module path defined in a package's {
"name": "react-layout-effect",
"version": "1.0.5",
"main": "dist/cjs/useLayoutEffect", // -> dist/cjs/useLayoutEffect.js ✅ Looking forward, when we support the Based on this, and given we provide the Workaround for projects Resolution of this import path under Metro can be overridden by configuring resolveRequest: (context, moduleName, platform) => {
// If needed, `&& platform !== 'web'`
if (moduleName === 'react-layout-effect') {
return {
filePath: './node_modules/react-layout-effect/dist/cjs/useLayoutEffect.native.js',
type: 'sourceFile',
};
}
return context.resolveRequest(context, moduleName, platform);
}, Fix for packages We recommend using the top-level Please raise an issue/PR to the package maintainer(s) that this pattern should be used instead of {
"name": "react-layout-effect",
"version": "1.0.5",
"main": "dist/cjs/useLayoutEffect",
"module": "dist/esm/useLayoutEffect",
+ "react-native": "dist/cjs/useLayoutEffectNative", |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When
main
in package.json ends with an extension (eg:.js
), Metro inadvertently looks for{filePathPrefix}.js
before{filePathPrefix}.native.js
because its resolution algorithm is incorrect.If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.Since there's an easy work around (exclude the extension), I can't spend time setting up a repo, but here's instructions for testing.
What is the expected behavior?
Check
.native.js
before.js
whenpreferNativePlatform
is true andmain
ends with.js
.Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
The text was updated successfully, but these errors were encountered: