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

React Native - Requiring unknown module "undefined" #681

Closed
zachrnolan opened this issue Apr 10, 2018 · 12 comments
Closed

React Native - Requiring unknown module "undefined" #681

zachrnolan opened this issue Apr 10, 2018 · 12 comments
Labels

Comments

@zachrnolan
Copy link

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

Bug

What is the current behavior?

When searching quickly and tapping elsewhere on a component, we are seeing the following error:

react_native_debugger_-connected__port_8081

I've found an issue on react-native that may shed more light on this issue:

What is the expected behavior?

App should not crash.

Other Details
"algoliasearch": "^3.26.0",
"react": "^16.3.0-alpha.1",
"react-native": "0.54.1",

@samouss
Copy link

samouss commented Apr 11, 2018

Thanks a lot for the notice! It looks like the issue arise when we import a module with the same path multiple times in the same file. By looking at the stack trace it happens with the clone function in AlgoliaSeachCore. In this file we import clone multiple times, because we scope the imports at the function level. I don't know the reason behind that? Maybe @vvo knows?

According to the issue, the problem is present on the version >= 0.54.x of React Native. With a version <= 0.53.x it should work (I didn't test though). You can stick to this version until we find a way to patch the library.

@samouss samouss added the bug label Apr 11, 2018
@Haroenv
Copy link
Contributor

Haroenv commented Apr 11, 2018

To be honest, this sounds like a bug in metro(?), rather than our library. I think we can change the imports to be top-level though, although that would mean they get imported at all times, and not just when you need the file. I think it might also have an impact on bundle size, but not sure if bundlers actually make use of the fact that require can be done in other spots than top-level.

Maybe we can also use the clone require top-level because it's used multiple times?

@samouss
Copy link

samouss commented Apr 11, 2018

Yes it's definitely an issue in metro. It might have a (little) impact in Node because the import will be executed when the file is required instead of when the function is called. But for the bundled files it should not impact the size (since the import are resolved at bundle time). We can even gain a little bytes since it will remove some lines.

@zachrnolan
Copy link
Author

Hey @samouss and @Haroenv, thanks for the quick replies. We are having a good amount of crashes in our app. Do you have any ETA for a fix? If it's coming soon, I can hold off downgrading RN. Appreciate the response!

@Haroenv
Copy link
Contributor

Haroenv commented Apr 13, 2018

We’ll need to investigate this deeply, making it a priority next week ok?

@zachrnolan
Copy link
Author

That sounds great. Thanks again for making this a priority.

@Haroenv
Copy link
Contributor

Haroenv commented Apr 16, 2018

So I took a look into this, the reason was indeed a bug in metro. You can see the commit in React Native master that bumps metro here: facebook/react-native@b02b167

What you can do is use the yarn resolution feature (https://yarnpkg.com/en/docs/selective-version-resolutions), or adding 0.30.2 as a dependency to your app to resolve the correct version of metro, with the fix.

Feel free to reopen if you tried that and it still didn't work.

@Haroenv Haroenv closed this as completed Apr 16, 2018
@zachrnolan
Copy link
Author

zachrnolan commented Apr 16, 2018

@Haroenv I tried adding resolutions to our project:

"resolutions": {
    "metro": "^0.30.2",
    "metro-core": "^0.30.2"
}

However, we are getting an error when the bundler starts (doesn't even give us a stack trace):
Cannot read property 'length' of undefined

If we don't go the resolutions route, but add metro and metro-core to our project package.json, will that change the version of metro that RN uses?

Any pointers would be greatly appreciated, thanks again!

@Haroenv
Copy link
Contributor

Haroenv commented Apr 16, 2018

You could try that out, but if you could give us access to a minimal reproduction of the problem, it would save a lot of time :). Otherwise I think the easiest would be to downgrade, wait, and upgrade

@GeoffreyPlitt
Copy link

Any update on this fix? It will affect every react-native developer who uses this soon...

@Haroenv
Copy link
Contributor

Haroenv commented Apr 24, 2018

Did you try using the specified metro version @GeoffreyPlitt? AFAIK this has been fixed on RN’s side, just not released yet. Otherwise you can stay on RN 0.53.x rather than 0.54.x and upgrade immediately to 0.55.x when that’s available :) if you have a project in which this can be reproduced, it would be very useful!

@samouss
Copy link

samouss commented Oct 4, 2018

This issue arise with the version 0.54.x of React Native.

To solve the issue you should either upgrade on 0.55.x or downgrade on the 0.53.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants