require-context.macro icon indicating copy to clipboard operation
require-context.macro copied to clipboard

ReferenceError: can't find variable require

Open vinipachecov opened this issue 5 years ago • 9 comments

Hi there!

I was following the storybook tutorial but using it with react native. Is it working for RN?

  1. I installed require-context.macro
  2. I installed babel-plugin-macros
  3. Configured storybook to load stories

Here is my config file for storybook

image

image

My package.json

image

image

Steps to reproduce:

  • Create react native app with react-native init
  • Install and configure storybook
  • install require-context.macro
  • configure stories as in storybook tutorial
  • see error

vinipachecov avatar Oct 29 '19 10:10 vinipachecov

Are your stories using CSF or old API?

kylemh avatar Oct 29 '19 18:10 kylemh

I’m using the old API. this error was occuring only when running react-native run-ios. Because storybook needs a platform to run appropriately this means it is not working. Storybook server itself is running fine.

vinipachecov avatar Oct 29 '19 18:10 vinipachecov

Why would run Storybook inside the native app 🤔

Do your storyshots work, or no?

kylemh avatar Oct 29 '19 20:10 kylemh

Well, on React Native it renders the components in the app. So to run storybook you have to run inside the app. At least this are the instructions in the official docs. Storyshots isn’t only for testing?

vinipachecov avatar Oct 29 '19 21:10 vinipachecov

Good to know about RN, Storyshots is definitely only for testing though.

You may want to head into the Storybook discord for more help! I'm not certain your issue relates to this macro or not, regardless I don't have the bandwidth to resolve your issue!

kylemh avatar Oct 29 '19 21:10 kylemh

@kylemh Thanks man, I'll try some help over there.

vinipachecov avatar Nov 11 '19 18:11 vinipachecov

Have the same problem any have you found anything @vinipachecov ?

zerubeus avatar Feb 24 '20 02:02 zerubeus

@zerubeus Not really. Storybook needs a platform so this require context will not work, it only works for web from what I've understood.

vinipachecov avatar Feb 24 '20 15:02 vinipachecov

I am not quite understanding how this macro overrides the require function? I can't find such code, so since this is a babel compile time only macro, it should work inside the RN app too.

pke avatar May 13 '22 12:05 pke