question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with webpack configuration - Material-UI decorator

See original GitHub issue

I am trying to use different npm modules (Material-ui, etc) , but they don’t seem load properly.

The error message I get is:

Cannot read property 'prepareStyles' of undefined
TypeError: Cannot read property 'prepareStyles' of undefined
    at RaisedButton.render (webpack:///~/material-ui/RaisedButton/RaisedButton.js:273:48)
    at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (webpack:///~/react/lib/ReactCompositeComponent.js:808:34)
    at ReactCompositeComponentWrapper._renderValidatedComponent (webpack:///~/react/lib/ReactCompositeComponent.js:835:34)
    at ReactCompositeComponentWrapper.performInitialMount (webpack:///~/react/lib/ReactCompositeComponent.js:372:30)
    at ReactCompositeComponentWrapper.mountComponent (webpack:///~/react/lib/ReactCompositeComponent.js:260:21)
    at Object.mountComponent (webpack:///~/react/lib/ReactReconciler.js:47:35)
    at ReactDOMComponent.mountChildren (webpack:///~/react/lib/ReactMultiChild.js:240:44)
    at ReactDOMComponent._createInitialChildren (webpack:///~/react/lib/ReactDOMComponent.js:698:32)
    at ReactDOMComponent.mountComponent (webpack:///~/react/lib/ReactDOMComponent.js:523:12)
    at Object.mountComponent (webpack:///~/react/lib/ReactReconciler.js:47:35)

I am using Meteor, hence the only Webpack configuration I have is the one for Storybook:

//Webpack configuration
const path = require('path');
module.exports = {
    module: {
        loaders: [
            {
                test: /\.css?$/,
                loaders: [
                    'style', 'raw'
                ],
                include: path.resolve(__dirname, '../')
            }
        ]
    },
    resolve: {
        extensions: [
            '', '.js', '.jsx'
        ]
    }
};

Here is the story:

import React from 'react';
import {storiesOf, action} from '@kadira/storybook';
import {setComposerStub} from 'react-komposer';
import FileUploader from '../file_uploader.jsx';

storiesOf('core.FileUploader', module).add('default view', () => {
    return (<FileUploader/>);
})

Here is the component:

import React from 'react';
import DropZone from 'dropzone';
import {RaisedButton, FontIcon} from 'material-ui';

class FileUploader extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        const {imageFiles} = this.props;

        return (
            <div>
                <DropZone className="drop-zone">
                    <RaisedButton label="Upload Pictures" icon={<FontIcon className="fa fa-upload"/>}/>
                    <p>
                        <small>Drop here the product pictures in
                            <code>jpeg</code>
                            or
                            <code>png</code>
                            format, with size less or equal to 2MB</small>
                    </p>
                </DropZone>
                <div className="image-preview">
                    {imageFiles && imageFiles[0]
                        ? imageFiles.map((image) => {
                            return (
                                <div className="image-wrapper"><img src={image.preview
                                    ? image.preview
                                    : image.link()}/></div>
                            );
                        })
                        : <div>
                            <i className="fa fa-camera"></i>{' Preview Images'}</div>}
                </div>
            </div>
        );
    }
}

export default FileUploader;

What I am missing?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
tinybugcommented, Sep 21, 2016

@arunoda nice!

import {storiesOf, action, addDecorator} from '@kadira/storybook';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';

const muiThemeDecorator = (story) => (
  <MuiThemeProvider>
    {story()}
  </MuiThemeProvider>
);

addDecorator(muiThemeDecorator);

@PolGuixe you can work like this.

1reaction
Fer0xcommented, Feb 23, 2017

That’s because of calling injectTapEventPlugin(); on each re-render. Just wrap it with try/catch.

try {
  injectTapEventPlugin();
} catch (e) {}

addDecorator(story => (
  <MuiThemeProvider>
    {story()}
  </MuiThemeProvider>
));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Problems with webpack configuration - Material-UI decorator
I am trying to use different npm modules (Material-ui, etc) , but they don't seem load properly. The error message I get is:...
Read more >
React + Material UI + Typescript + Webpack + SSR not ...
Everything was working fine until I tried to add Material UI to it. My directory structure is this: app/ build/ * This is...
Read more >
Integrate Material UI + Adjust Webpack: Building a ... - YouTube
Hello everyone! In this video, we integrate a UI library into our application and extend the Webpack configuration to allow loading of css ......
Read more >
Troubleshooting - Material UI
This document covers known issues and common problems encountered when migrating from Material UI v4 to v5.
Read more >
How to use ReactJS with Webpack 4, Babel 7, and Material ...
Before we go ahead and start messing with the Webpack config file, let's first install some stuff that we are going to need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found