-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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-configuration does not work with TS or React Native? #28802
Comments
I experience the same situation with Especially on a fresh project, which is setup like @fwielstra described, the storyboard integration via nx doesn't work on React Native. |
i create a pr in your repo to fix the storybook. https://github.com/fwielstra/nx-react-native-storybook-bug/pull/1/files# I submitted a pr to fix this, but here are the steps to manually fix it: webpackif you chose webpack as bundler for your react-native app, after you run the command
or you can use https://www.npmjs.com/package/@storybook/addon-react-native-web, after you install
viteif you chose
then you can run the command if you already run the command, you might need to change
|
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
UPDATE
I've started a new project from scratch with a similar setup using the "React Native" recipe:
Added a Button component, used it in the app, all good. Then adding Storybook using the @nx/storybook documentation:
Then starting Storybook using
This leads to the following compiler error:
According to this issue, this should be fixable by adding an
alias
in theresolve
section of the Vite config, but this is all set up by the generators already. I'm stuck at this point now. I've uploaded the whole project here: https://github.com/fwielstra/nx-react-native-storybook-bug, if anyone can point out anything I've missed, that would be appreciated.Current Behavior
I have an existing React Native monorepo with three apps and a dozen libraries. I've built my own 'component demo' app because when we started, Storybook didn't work well with React Native yet, however this should have improved by now.
I've followed the instructions on the @nx/storybook page:
The wizard and output:
The first signal something is up is the line "Please run 'nx run @nx/react:storybook-configuration components' instead.". It doesn't generate configuration that works with React Native components, but does something with vite (which is otherwise unused in our application) and vanilla react instead, while I expect that it should generate a Metro configuration and the like.
Anyway, then I started Storybook using
nx run components:storybook
So far so good; it says
No story files found for the specified pattern: libs/components/src/lib/**/*.@(mdx|stories.@(js|jsx|ts|tsx))
but that's alright because I don't have alib
folder undersrc
, it's all straight undersrc
. I updated the config accordingly:stories: ['../src/**/*.@(mdx|stories.@(js|jsx|ts|tsx))'],
and restarted Storybook:
nx run components:storybook
I had Storybook generate a story for one of my components:
Then I restarted / reloaded Storybook, and this is where things fall apart:
In the Storybook web interface itself:
In the terminal:
One possible solution suggested by the internet is to add
"@babel/preset-typescript"
to.babelrc
(in our codebase we still usebabel.config.json
), but this does not seem to get picked up, nor does it appear anywhere else in our exclusively Typescript project. For completeness, this is thebabel.config.json
from thecomponents
library:I hope that it's something simple or something I missed from the (incredibly straightforward) instructions. I've followed similar instructions from 3rd party websites as well.
One other thing I can try is to generate an Expo app using
nx g @nx/expo:app apps/storybook
, then try and apply the configuration changes from the example React Native / Storybook template, but I'd prefer if things like this work out of the box.Expected Behavior
Adding
@nx/storybook
and runningnx g @nx/react-native:storybook-configuration components
should generate a working and running Storybook instance for an existing React Native component library.GitHub Repo
No response
Steps to Reproduce
react native
variant under the "Generating Storybook Configuration" headinglibs/components/.storybook/main.ts
, remove the/lib
path part from thestories
fieldnx run components:storybook
Nx Report
NX Report complete - copy this into the issue template
Node : 18.20.4
OS : darwin-arm64
Native Target : aarch64-macos
npm : 10.7.0
nx (global) : 20.0.0
nx : 20.0.8
@nx/js : 20.0.8
@nx/jest : 20.0.8
@nx/eslint : 20.0.8
@nx/workspace : 20.0.8
@nx/cypress : 20.0.8
@nx/devkit : 20.0.8
@nx/eslint-plugin : 20.0.8
@nx/react : 20.0.8
@nx/react-native : 20.0.8
@nx/storybook : 20.0.8
@nx/vite : 20.0.8
@nx/web : 20.0.8
typescript : 5.5.2
Community plugins:
@diogovcs/stryker-mutator : 0.2.6
Failure Logs
15:45:43 [vite] Internal server error: /Users/[my project folder]/libs/components/src/Buttons/PrimaryButton.stories.tsx: Unexpected token, expected "from" (1:12)
Package Manager Version
No response
Operating System
Additional Information
I know this is a lot of information to parse and yet probably not enough information, and I don't have a reproduction yet without starting a new project from scratch emulating the circumstances of the large project I'm working in right now. It's possible that if I start from scratch, everything will work out of the box, but I can't be sure. I just hope there's something obvious I missed.
The text was updated successfully, but these errors were encountered: