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

Confusing error message if stories import React weirdly #416

Closed
tomjakubowski opened this issue Sep 1, 2016 · 2 comments
Closed

Confusing error message if stories import React weirdly #416

tomjakubowski opened this issue Sep 1, 2016 · 2 comments

Comments

@tomjakubowski
Copy link

tomjakubowski commented Sep 1, 2016

First of all, thank you so much for react-storybook! It's truly amazing :-)

I'm still getting used to ES6 syntax and all that (~2 years out of the web dev game), so I messed up my imports in my stories file and ended up with something like this:

import { React } from 'react';
import { storiesOf, action } from '@kadira/storybook';
import OrdinalSwapper from '../OrdinalSwapper';

storiesOf('OrdinalSwapper', module)
  .add('now with action logging!', () =>
       <OrdinalSwapper count="10" onSwap={action('swapped')}/>
      );

(note the extra braces around React, which I imagine is doing something like a destructuring assignment)

When I use this stories file, I get this error in react-storybook:

Cannot read property 'createElement' of undefined
TypeError: Cannot read property 'createElement' of undefined
    at eval (webpack:///:6:22)
    at renderMain (webpack:///~/@kadira/storybook/dist/client/preview/render.js:84:38)
    at renderPreview (webpack:///~/@kadira/storybook/dist/client/preview/render.js:99:10)
    at Array.renderUI (webpack:///~/@kadira/storybook/dist/client/preview/index.js:89:26)
    at Object.dispatch (webpack:///~/redux/lib/createStore.js:186:19)
    at ConfigApi._renderMain (webpack:///~/@kadira/storybook/dist/client/preview/config_api.js:46:24)
    at render (webpack:///~/@kadira/storybook/dist/client/preview/config_api.js:64:17)
    at ConfigApi.configure (webpack:///~/@kadira/storybook/dist/client/preview/config_api.js:80:9)
    at Object.eval (webpack:///storybook/config.js:4752:2)
    at eval (webpack:///storybook/config.js:4752:2)

I noticed that if I neglect to import React at all, the error message is much nicer (and so is probably special-cased by something in react-storybook):

React is not defined
ReferenceError: React is not defined
    at eval (webpack:///:6:10)
    at renderMain (webpack:///~/@kadira/storybook/dist/client/preview/render.js:84:38)
    at renderPreview (webpack:///~/@kadira/storybook/dist/client/preview/render.js:99:10)
    at Array.renderUI (webpack:///~/@kadira/storybook/dist/client/preview/index.js:89:26)
    at Object.dispatch (webpack:///~/redux/lib/createStore.js:186:19)
    at ConfigApi._renderMain (webpack:///~/@kadira/storybook/dist/client/preview/config_api.js:46:24)
    at render (webpack:///~/@kadira/storybook/dist/client/preview/config_api.js:64:17)
    at ConfigApi.configure (webpack:///~/@kadira/storybook/dist/client/preview/config_api.js:80:9)
    at Object.eval (webpack:///storybook/config.js:4752:2)
    at eval (webpack:///storybook/config.js:4752:2)

Would it be possible to check for the first error (mis-import of React) as you check for the latter (forgotten import of React)?

@arunoda
Copy link
Member

arunoda commented Sep 1, 2016

Yep. That's messages coming from webpack and react.
Unfortunately we don't have much control over them.

@arunoda arunoda closed this as completed Sep 1, 2016
@dongmingchao
Copy link

dongmingchao commented Oct 7, 2019

tsconfig.json => Set"esModuleInterop": trueinstead. About
for more people

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

No branches or pull requests

3 participants