Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUsage with Storybook and react-native-web #2201
Comments
|
Judging based on your comment only, I have no way to determine where |
|
I'm having a similar issue getting react-native-elements working in my typescript monorepo. It seems to be related to the webpack config but I just can't seem to get it all working together. I've got a repo structure like:
My typescript projects are setup with references, and the components project is using react-native-elements and I've added the webpack config described here https://react-native-elements.github.io/react-native-elements/docs/web_usage.html. Everything compiles and runs fine in react-native but in the web project i get:
It's choking on the jsx unfortunately. I compared all of the webpack config objects with the https://github.com/react-native-elements/create-react-app-example project but can't seem to overcome this error. Anyone have any ideas? |
|
After a lot of reading / writing of config files I finally got this to work. It was an issue with the paths that I was resolving for the babel loader. Here is what I ended up with, which seems fairly general. I'll need to see if I can apply it to storybook as well. // require.resolve will resolve to the entry point of the module
// but we just want the folder
function resolveModuleDir(moduleName) {
const pattern = new RegExp(`(?<=${moduleName}).*$`);
return require.resolve(moduleName).replace(pattern, "");
}
module.exports = {
webpack: (config, env) => {
const newConfig = override(
removeModuleScopePlugin(),
...addBabelPlugins(
["@babel/plugin-proposal-decorators", { "legacy": true }],
['@babel/plugin-proposal-class-properties', { "loose": true }],
'babel-plugin-react-native-web'
),
addWebpackPlugin(new webpack.DefinePlugin({ __DEV__: env !== 'production' })),
babelInclude([
resolveModuleDir('react-native-elements'),
resolveModuleDir('react-native-vector-icons'),
resolveModuleDir('react-native-ratings'),
...appIncludes
])
)(config);
return newConfig;
}
} |
|
@neilgamb I ended up getting my storybook working with react-native-elements. It was just a matter of getting the right modules transpiled by babel. The webpack.config.js in my module.exports = ({ config }) => {
const oneOfRules = config.module.rules[3];
const babelLoader = oneOfRules.oneOf[1];
babelLoader.include = [
...babelLoader.include,
'node_modules/react-native-elements',
'node_modules/react-native-vector-icons',
'node_modules/react-native-ratings'
]
return config;
}You may also want to confirm that you either have the Hope that helps. |
|
in case it might help someone I had to run into a few more steps.
Example webpack rule config that works for me:
|
|
wonderful! I'm coming back to this after working on something else for a few weeks. I will give this a shot a report back. Thanks for your input @cjam |
|
Hi all, i still have problem, i hope somebody can give me some help or idea. I created a react storybook (NO with react-create-app), then i add the library react-native-web, configured the storybook webpack and my babel, and everything works fine. THEN i added the react-native-elements lib, i configured webpack follow the instructions found here and on the official docs, but i still have a error (ONLY WHEN I IMPORT A FILE USING 'react-native-component') like this :
image attached from storybook maybe is more clear this is my babel config
and this is my webpack inside ./storybook
Any help will be very appreciated guys :) |
|
I start from the official 2018 guide The author proposed a solution in this commit I just simply add // Process application JS with Babel.
// The preset includes JSX, Flow, and some ESnext features.
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
//include: paths.appSrc,
include: [
paths.appSrc,
`${paths.appNodeModules}/react-native-elements`,
`${paths.appNodeModules}/react-native-vector-icons`,
`${paths.appNodeModules}/react-native-ratings`,
], |
|
tnx @Aria461863631 , i re-check my config |

I'm looking to create a docs site / component library using storybook. I have followed the instructions here: https://react-native-elements.github.io/react-native-elements/docs/web_usage.html
but when I compile the storybook, I'm getting the following error:
Module parse failed: Unexpected token (61:11) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.Your Environment (please complete the following information):