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 Storybook doesn't work with iOS/Android Hermes Engine in React Native v0.64.0 #152

Closed
oleksandr-dziuban opened this issue Mar 16, 2021 · 42 comments
Labels
bug Something isn't working has workaround

Comments

@oleksandr-dziuban
Copy link

Describe the bug
When I run react-native storybook with React Native v0.64.0 and Hermes enabled for iOS/Android platform it throws en error:

RangeError: Maximum call stack size exceeded, js engine: hermes
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. 
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

If Hermes JS Engine disabled everything works fine for iOS/Android platforms.

To Reproduce
Steps to reproduce the behavior:

  1. Setup basic React Native Storybook app according to Docs
  2. Use React Native v0.64 app template
  3. Enable iOS Hermes JS engine according to React Native docs
  4. Enable Android Hermes JS engine according to React Native docs
  5. Assemple iOS and Android app
  6. App will be compiled succesfully, but when app starts, JS error thrown.

Expected behavior
App is running storybook correctly

Screenshots
App throws an error and cannot be bootstrapped.

System:

 System:
    OS: macOS 11.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.15.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - /usr/local/bin/npm
  Browsers:
    Chrome: 89.0.4389.82
    Edge: 89.0.774.54
    Firefox: 84.0.2
    Safari: 14.0.3
  npmPackages:
    @storybook/addon-knobs: 5.3.21 => 5.3.21 
    @storybook/addon-ondevice-knobs: 5.3.25 => 5.3.25 
    @storybook/cli: 5.3.21 => 5.3.21 
    @storybook/react-native: 5.3.25 => 5.3.25 
@wenzelua
Copy link

same here

@balovbohdan
Copy link

Faced the same issue.

@dannyhw
Copy link
Member

dannyhw commented Mar 20, 2021

Hey guys thanks for reporting these issues, I haven't had a chance to test this yet. I wasn't aware of any incompatibly with hermes, I'll look into it.

Are you able to provide a repository that reproduces the issue?

@dannyhw
Copy link
Member

dannyhw commented Mar 20, 2021

If anyone is able to offer their time to help on this issue that would be really great, it might take some time for me alone to test everything with 0.64. This is all done in my free time outside of work hours so please be patient with me 🙏 .

I've just made a fresh react native project for testing this out and I'll be doing some debugging tonight.

@dannyhw
Copy link
Member

dannyhw commented Mar 20, 2021

@oleksandr-dziuban @SlaUA @balovbohdan I just tried this on my machine and I had no issues getting it working without making any changes.

Could you please share a repository where you are able to produce this error?

@dannyhw dannyhw added bug Something isn't working needs reproduction labels Mar 20, 2021
@dannyhw
Copy link
Member

dannyhw commented Mar 20, 2021

I've found a bit of an issue when using the code generated by cli alongside existing projects, I'm not sure if it's related however I think I will need to update the generator in the cli.

If it is relatedThere are some changes you could make that might resolve your issue however I need to see some of your code to be sure.

@oleksandr-dziuban
Copy link
Author

I've found a bit of an issue when using the code generated by cli alongside existing projects, I'm not sure if it's related however I think I will need to update the generator in the cli.

If it is relatedThere are some changes you could make that might resolve your issue however I need to see some of your code to be sure.

Hello @dannyhw Sorry, can't share a repo, as this e-commerce project is under NDA. Which issues did you find and what we can do to help you to test it?
Thanks

@dannyhw
Copy link
Member

dannyhw commented Mar 21, 2021

@oleksandr-dziuban its not necessary to share the project itself but if you could try to recreate the issue in a fresh project and then share that with me it would be really useful.

Otherwise you could share just the parts of the code that include the storybook configuration and the place where you use the component returned from getStorybookUI. Of course feel free to take out any code specific to your project and modify it so that it doesn't breach the nda.

@dannyhw
Copy link
Member

dannyhw commented Mar 22, 2021

Just want to re-iterate that in order to fix any issues I really need someone to show me an example of this not working so that I can help the best way possible. Doesn't need to be the issue creator or any real world code, just any example or steps to reproduce. I've not found any issues with hermes or 0.64 personally when I try it so I need to understand better where this issue is coming from.

@dannyhw
Copy link
Member

dannyhw commented Mar 22, 2021

@oleksandr-dziuban in your issue description you have given some steps but its not clear to me exactly the steps you followed.

"Setup basic React Native Storybook app according to Docs" - which docs are you refering to? the readme?
"Use React Native v0.64 app template" - which template are you using? typescript or normal? expo or not expo?

@apostopher
Copy link

apostopher commented Mar 24, 2021

@dannyhw here is the repo to reproduce the errors below: Storybook with hermes please see the commit messages for the steps i followed.

Note that I could reproduce this error only when using the storybook server and on device UI is disabled.

@dannyhw
Copy link
Member

dannyhw commented Mar 24, 2021

@apostopher thanks a lot for providing this, it will definitely help a lot 👍.

@oleksandr-dziuban
Copy link
Author

@oleksandr-dziuban in your issue description you have given some steps but its not clear to me exactly the steps you followed.

"Setup basic React Native Storybook app according to Docs" - which docs are you refering to? the readme?
"Use React Native v0.64 app template" - which template are you using? typescript or normal? expo or not expo?

Readme, yes, simple project without typescript and without expo

@oleksandr-dziuban
Copy link
Author

@dannyhw here is the repo to reproduce the errors below: Storybook with hermes please see the commit messages for the steps i followed.

Note that I could reproduce this error only when using the storybook server and on device UI is disabled.

For me it reproduced without storybook server and on device ui enabled

@dannyhw
Copy link
Member

dannyhw commented Mar 26, 2021

@oleksandr-dziuban if you could provide an example of this then that would help alot, so far I haven't been able to reproduce anything without the storybook server

@dannyhw
Copy link
Member

dannyhw commented Mar 26, 2021

@apostopher I was able to see the issue when running your example. It seems the issue is caused by trying to connect with the server, perhaps hermes doesn't support web sockets? Anyway I'm looking into it.

@dannyhw
Copy link
Member

dannyhw commented Mar 26, 2021

@oleksandr-dziuban @apostopher I found something interesting when I was investigating and I was able to make the error go away. From what I can tell the issue is that "JSON" was coming up as undefined, through some googling I found that hermes might have an issue with "inlineRequires". When I change metro config to have inlineRequires: false the issue seems to go away.

@apostopher
Copy link

@dannyhw thanks mate! i tested it with inlineRequires: false and it builds perfectly. i'll try to make it work with inlineRequires. I read about it and it seems its an issue with core-jsandinlineRequires`. But that is not related to this issue.

Thanks a lot for investigating. i can confirm that it works for me now.

@oleksandr-dziuban
Copy link
Author

oleksandr-dziuban commented Mar 30, 2021

@dannyhw Thanks a lot for thsi research! it works perfectly with inlineRequires: false.
Are you planning to fix inlineRequires: true case ?

@dannyhw
Copy link
Member

dannyhw commented Mar 30, 2021

@oleksandr-dziuban In short yes I would love to fix that case, at the moment I'm just not sure how.

If its related to corejs it would be difficult to resolve. The storybook client api is using babel transforms to support older versions of javascript and I think even the typescript compiler will transform using corejs. Even if I were to provide the react-native code without transforms there isn't a way that I can get the client-api without those babel transformations.

If I can figure out what specifically causes the issue I'll be able to say more clearly though.

@oleksandr-dziuban
Copy link
Author

@oleksandr-dziuban In short yes I would love to fix that case, at the moment I'm just not sure how.

If its related to corejs it would be difficult to resolve. The storybook client api is using babel transforms to support older versions of javascript and I think even the typescript compiler will transform using corejs. Even if I were to provide the react-native code without transforms there isn't a way that I can get the client-api without those babel transformations.

If I can figure out what specifically causes the issue I'll be able to say more clearly though.

Thanks

@henrymoulton
Copy link

@dannyhw thanks for the workaround.

Is this something that might be resolved in V6?

@dannyhw
Copy link
Member

dannyhw commented May 24, 2021

@henrymoulton I hope so, however I'll have to do some debugging since I've not identified the cause yet.

@henrymoulton
Copy link

henrymoulton commented May 25, 2021

Going to try and dig, I've got a version I just setup where Android works with a fresh setup

image

https://github.com/henrymoulton/storybook-hermes

Will branch off main and try enabling Hermes on iOS see if that causes a crash.

@henrymoulton
Copy link

henrymoulton commented May 25, 2021

Yep that works...

https://github.com/henrymoulton/storybook-hermes/tree/ios-hermes-enabled

image

@apostopher I noticed that your repro uses TypeScript whereas mine uses vanilla JS... other than that couldn't spot differences

@henrymoulton
Copy link

@dannyhw
Copy link
Member

dannyhw commented May 25, 2021

@henrymoulton I noticed a difference in the lock diff that that one has react native 0.64.1 and the other 0.64. Is it possible that there was a fix in 64.1?


edit: I checked the release notes and 64.1 just includes the fix for xcode 12.5

@dannyhw
Copy link
Member

dannyhw commented Sep 13, 2021

We believe that this is fixed in the v6 alpha and using inlineRequires:false is a workaround for 5.3. For those reason I'll close this issue. Please let us know if you continue to have this issue in the v6 alpha.

@hannojg
Copy link

hannojg commented Jun 26, 2022

@dannyhw
Hey, i just tested the latest alpha version. I still have to set inlineRequires: false, or otherwise get the named exception thrown. Can you reproduce on your end? Otherwise i will provide a reproduction!

(react native version 0.68.2)

@dannyhw
Copy link
Member

dannyhw commented Jun 27, 2022

@hannojg hey, I haven't come across this issue in a while and I'm not totally sure why it happens. I think it has something to do with the way that we import stories. Does this happen on a fresh project also?

@JSONRice
Copy link

JSONRice commented Oct 6, 2022

@dannyhw great suggestion on that inlineRequires: false That ended up working for me after I spent a day on this. The documentation could really be consolidated and cleaned up. Wish I had more time to assist but I'm heads down on some tight deadlines. Keep up the good work! Risa's tutorial helped out but is now partially outdated.

@henrymoulton
Copy link

henrymoulton commented Mar 2, 2023

@dannyhw noticed this issue closed, we don't want to set inlineRequires: false as that reduces some performance optimisation that's possible in RN, is there a workaround? https://reactnative.dev/docs/ram-bundles-inline-requires

Is there a fix in v5/6

@dannyhw
Copy link
Member

dannyhw commented Mar 2, 2023

@henrymoulton Not sure why this happens exactly but I never run into this issue on v6 so I guess using the release candidate version maybe 😅

@dannyhw
Copy link
Member

dannyhw commented Mar 2, 2023

Also as far as I understand ram bundles don't work on hermes so I'm not sure that would be very widely used

@henrymoulton
Copy link

Even without the RAM format, inline requires can lead to startup time improvements, because the code within VeryExpensive.js will only execute once it is required for the first time.

@dannyhw my understanding is that you can still use inline requires without RAM format and the docs encourage it.

@dannyhw
Copy link
Member

dannyhw commented May 2, 2023

@henrymoulton yeah but i was talking about not using ram bundles with hermes.

Anyway inline requires works you just need to add sbmodern to your metro resolvers config

module.exports = {
  /* existing config */
  resolver: {
    resolverMainFields: ['sbmodern', 'react-native', 'browser', 'main'],
  },
};

This only works on v6.5 though

@CavidM
Copy link

CavidM commented Jun 2, 2023

Now app starts but can't run with redux dispatch method. I'm using redux toolkit slices. Commenting actions which is exported from slice solves the issue.

@dannyhw
Copy link
Member

dannyhw commented Jun 2, 2023

@CavidM sorry but I don't see how that would be related to this, if you can explain the link between redux slices and storybook I'm happy to try and debug.

@sekoyo
Copy link

sekoyo commented Jun 6, 2023

I upgraded from 6 to 6.5 (semver would suggest this is a non-breaking update) and added resolverMainFields: ['sbmodern', 'react-native', 'browser', 'main'], but first I had to add @storybook/core-common to fix an exception about it missing, and now I have Unable to resolve module react-dom from .../node_modules/@storybook/preview-web/dist/modern/renderDocs.js: react-dom could not be found within the project or in these directories:

Seems like it started to think I'm using the DOM. Anyone have some upgrade tip for going to 6.5? I need inlineRequires: true to load local files in react-native-webview

@dannyhw
Copy link
Member

dannyhw commented Jun 6, 2023

@dominictobias unfortunately you need to install react-dom since its used by a storybook dependency.

You can put inlinesRequires:true as long as you have sbmodern in your resolverMainfields.

@sekoyo
Copy link

sekoyo commented Jun 6, 2023

@CavidM sorry but I don't see how that would be related to this, if you can explain the link between redux slices and storybook I'm happy to try and debug.

Ah great it works now thanks!

@younthu
Copy link

younthu commented Sep 27, 2023

works with following config in metro.config.js:

module.exports = { transformer: { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, inlineRequires: true, }, }), }, resolver: { resolverMainFields: ['sbmodern', 'react-native', 'browser', 'main'], // https://github.com/storybookjs/react-native/issues/152#issuecomment-1578970298 }, };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround
Projects
None yet
Development

No branches or pull requests