Describe the bug
I'm trying to use require.context for react-native but it throws an error. I've installed babel-plugin-require-context-hook and added it to babel.config.js
require('babel-plugin-require-context-hook/register')();
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['require-context-hook'],
};
But throwing an error:
error: bundling failed: Error: Unable to resolve module `path` from `/Users/.../node_modules/babel-plugin-require-context-hook/register.js`: Module `path` does not exist in the Haste module map
To Reproduce
Steps to reproduce the behavior:
const req = require.context('../app/components', true, /\.stories.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}
configure(loadStories, module);
react-native run-android or ios and in parallel, run yarn storybookExpected behavior
Loop thru the app/components/ files with regex /\.stories.js$/
What i've tried so far:
AFAIK this isn't possible in RN, but my info may be outdated (RN world moving fast...)
@shilman okay understood, but do you happen to know a workaround?
From the docs: https://storybook.js.org/docs/basics/writing-stories/
The React Native packager resolves all the imports at build-time, so it鈥檚 not possible to load modules dynamically. There is a third party loader react-native-storybook-loader to automatically generate the import statements for all stories.
Most helpful comment
From the docs: https://storybook.js.org/docs/basics/writing-stories/