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

React-Native: "Can't find variable: document" #4063

Closed
sregg opened this issue Aug 23, 2018 · 13 comments
Closed

React-Native: "Can't find variable: document" #4063

sregg opened this issue Aug 23, 2018 · 13 comments

Comments

@sregg
Copy link

sregg commented Aug 23, 2018

Bug

Getting "Can't find variable: document" error when launching React-Native app with storybook.

image

Steps to reproduce

  1. Create React_Native 0.56 app: react-native init TestStoryBookReactNative
  2. Install storybook CLI 4.0.0-alpha.16: npm i -g @storybook/[email protected]
  3. Install storybook in project: cd TestStoryBookReactNative and getstorybook
  4. Run storybook: npm run storybook
  5. See this error: error: 'Plugin 0 provided an invalid property of "default"' when using with React Native + TypeScript #3897
  6. Install Babel 7: yarn remove babel-core and yarn add -D @babel/[email protected] [email protected]
  7. Run storybook again: npm run storybook no more error
  8. Check that http://localhost:7007/ works
  9. Launch iOS app: react-native run-ios
  10. Get "Can't find variable: document" error

Please specify which version of Storybook and optionally any affected addons that you're running

my package.json:

{
  "name": "TestStoryBookReactNative",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "storybook": "storybook start -p 7007"
  },
  "dependencies": {
    "react": "16.4.1",
    "react-native": "0.56.0"
  },
  "devDependencies": {
    "@babel/core": "7.0.0-beta.47",
    "@storybook/addon-actions": "^4.0.0-alpha.16",
    "@storybook/addon-links": "^4.0.0-alpha.16",
    "@storybook/addons": "^4.0.0-alpha.16",
    "@storybook/react-native": "^4.0.0-alpha.16",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "23.4.2",
    "babel-preset-react-native": "^5",
    "babel-runtime": "^6.26.0",
    "jest": "23.5.0",
    "prop-types": "^15.6.2",
    "react-dom": "16.4.1",
    "react-test-renderer": "16.4.1"
  },
  "jest": {
    "preset": "react-native"
  }
}
@ritz078
Copy link
Contributor

ritz078 commented Aug 27, 2018

did you find any solution for this?

@sregg
Copy link
Author

sregg commented Aug 27, 2018

@ritz078 nope, I gave up...

@chrisnojima
Copy link

I don't have a fix for this yet but what I've seen so far
importing {storiesOf} from '@storybook/react-native' pulls in a series of imports

@storybook/react-native/dist/index.js
dist/preview/index.js
components/dist/index.js
which ultimately pulls in input which pulls in react-textarea-autosize. This seems like the native side is getting mixed with the web ui side again (similar to #3068)

@igor-dv
Copy link
Member

igor-dv commented Aug 28, 2018

Does it happen without any addons as well?

@Gongreg
Copy link
Member

Gongreg commented Aug 30, 2018

Hey. It happens always:
Reason:

Addons/index.js

import { TabWrapper } from '@storybook/components';

This line brings many things that are not relevant to RN and is part of global import.

In first place no ui should be inside @storybook/addons at all

@igor-dv

@igor-dv
Copy link
Member

igor-dv commented Aug 30, 2018

So, do we have a bug?

@Gongreg
Copy link
Member

Gongreg commented Aug 30, 2018

Yes :)

@igor-dv
Copy link
Member

igor-dv commented Aug 30, 2018

🤦‍♂️

I think we need to add some test that will prevent this kind of bugs.

@Gongreg
Copy link
Member

Gongreg commented Aug 30, 2018

Simple sanity test would help a lot here. We could try to add detox tests in the future for React Native.

@igor-dv
Copy link
Member

igor-dv commented Aug 30, 2018

I am fixing this.

chrisnojima added a commit to keybase/storybook-addons-hotfix that referenced this issue Aug 30, 2018
chrisnojima added a commit to keybase/client that referenced this issue Aug 30, 2018
@ndelangen
Copy link
Member

@igor-dv @Gongreg and i talked a bit about this, we think the best method to fix this is by moving this code to /lib/ui somewhere:

https://github.com/storybooks/storybook/blob/master/lib/addons/src/index.js#L56-L62

@Gongreg
Copy link
Member

Gongreg commented Sep 1, 2018

Hello,

4.0.0-alpha.20 was released. It should solve this issue.

@aleclarson
Copy link

aleclarson commented Oct 3, 2019

I'm seeing this error in @storybook/[email protected]

edit: Nevermind, my fault, same as #4642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants