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

fix: Fix #120 (running "yarn web" on Expo fails). #251

Merged
merged 1 commit into from
Sep 12, 2021

Conversation

lauriharpf
Copy link
Contributor

Issue: Fix #120. The "dist" output in the v6 alpha packages contains JSX and ESNext constructs. Browsers can't handle these natively, so "yarn web" fails on Expo. Fix by using slightly less modern constructs in our dist outputs.

What I did

Changed targets from ESNext to ES6 (which modern browsers can run without transpiling). Changed the jsx output settings to react from react-native so that the JSX can also be rendered by browsers in addition to React Native. See https://www.typescriptlang.org/docs/handbook/jsx.html#basic-usage .

How to test

  1. Pull this branch
  2. Run yarn prepareAll in the root of directory of this branch
  3. Set up an Expo v6 alpha project using the instructions in docs: Fixes #247 by editing the v6 alpha guide with instructions on how to set up with Expo #250, but with a small twist: Instead of doing
yarn add @storybook/react-native@next \
            @react-native-async-storage/async-storage \
            @storybook/addon-ondevice-actions@next \
            @storybook/addon-ondevice-controls@next \
            @storybook/addon-ondevice-backgrounds@next \
            @storybook/addon-ondevice-notes@next \
            @storybook/addon-actions \
            @react-native-community/datetimepicker \
            @react-native-community/slider \
            @storybook/addon-controls

point the React Native Storybook dependencies to your local files:

yarn add /REPLACE-WITH-PATH-TO-MY-REACT-NATIVE-STORYBOOK-REPO/app/react-native \
            @react-native-async-storage/async-storage \
            /REPLACE-WITH-PATH-TO-MY-REACT-NATIVE-STORYBOOK-REPO/addons/ondevice-actions \
            /REPLACE-WITH-PATH-TO-MY-REACT-NATIVE-STORYBOOK-REPO/addons/ondevice-controls  \
            /REPLACE-WITH-PATH-TO-MY-REACT-NATIVE-STORYBOOK-REPO/addons/ondevice-backgrounds \
            /REPLACE-WITH-PATH-TO-MY-REACT-NATIVE-STORYBOOK-REPO/addons/ondevice-notes  \
            @storybook/addon-actions \
            @react-native-community/datetimepicker \
            @react-native-community/slider \
            @storybook/addon-controls
  1. Run yarn web in the root directory of the Expo v6 alpha project that you set up. The project should start up in your browser. If you repeat this with the next-6.0 branch instead of this branch, yarn web should cause an error similar to this:
/Users/lauriharpf/Repos/lauriharpf/appName/node_modules/@storybook/react-native/dist/preview/Preview.js 12:14
Module parse failed: Unexpected token (12:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const STORAGE_KEY = 'lastOpenedStory';
| export default class Preview {
>     _clientApi;
|     _storyStore;
|     _addons;
  1. Experiment with yarn ios and yarn android in the Expo project as well as yarn ios and yarn android in the vanilla React Native project at/examples/native in this repo. All should work.
  • Does this need a new example in examples/native? no, not in my opinion
  • Does this need an update to the documentation? no, not in my opinion

@dannyhw
Copy link
Member

dannyhw commented Aug 14, 2021

Overall seems like the right move, just a few small questions :)

@lauriharpf
Copy link
Contributor Author

Overall seems like the right move, just a few small questions :)

Awesome 👍 . Ask away, will try to answer the best I can :)

@dannyhw
Copy link
Member

dannyhw commented Aug 14, 2021

Overall seems like the right move, just a few small questions :)

Awesome 👍 . Ask away, will try to answer the best I can :)

I left the questions as review comments.

Copy link
Member

@dannyhw dannyhw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I thought the questions would show up without submitting the review. Overall I think I'm ok with these changes, just clarification on those points would be good 👍.

addons/ondevice-controls/tsconfig.json Show resolved Hide resolved
app/react-native/tsconfig.json Show resolved Hide resolved
The "dist" output in the v6 alpha packages contains JSX and ESNext constructs. Browsers can't handle these natively, so "yarn web" fails on Expo. Fix by using slightly less modern constructs in our dist outputs.
Copy link
Member

@dannyhw dannyhw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, the only thing I would say is that we need to apply this to the other addons also. I'll open a new PR with those changes.

addons/ondevice-controls/tsconfig.json Show resolved Hide resolved
@dannyhw dannyhw merged commit 6ad8dfd into storybookjs:next-6.0 Sep 12, 2021
@lauriharpf lauriharpf deleted the fix/yarn-web-in-expo branch September 13, 2021 05:13
dannyhw pushed a commit to raychanks/react-native that referenced this pull request Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-native-web 0.12.0+ doesn't work with storybook due to deprecated components
2 participants