Material-ui: Example in README throws can't resolve 'material-ui/Button'

Created on 23 Aug 2017  路  27Comments  路  Source: mui-org/material-ui

Problem description

Following the example on the README leads to:

Module not found: Can't resolve 'material-ui/Button'

Steps to reproduce

  1. Execute:
create-react-app example
cd example
yarn add material-ui@latest
// Modify App.js to include a <Button/> tag
yarn start

Example App.js:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Button from 'material-ui/Button';

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
        <Button>Example Button</Button>
      </div>
    );
  }
}

export default App;

Versions

  • Material-UI: ^0.19.0
  • React: ^15.6.1
  • Browser: Chrome 60.0.3112.101 (Official Build) (64-bit)
docs

Most helpful comment

Try npm install material-ui@next --save and restart the server, it should work!

All 27 comments

You have mixed yarn add material-ui@latest@ and yarn add material-ui@next. Any idea how we could prevent such confusion? Otherwise, we can close.

We just use both versions material-ui and naterial-ui-next

Hi @oliviertassinari

I am getting this error after

npm install material-ui --save
yarn 
yarn start

offending line is:

import Button from 'material-ui/Button';

i have same problem when i
import Button from 'material-ui/Button';
i tried both npm and yarn,
and i didnt found 'Button' module @ node_module/material-ui folder

i have same problem when i
import Button from 'material-ui/Button';
i tried both npm and yarn,
and i didnt found 'Button' module @ node_module/material-ui folder

I'm having exactly the same problem.

I have same problem when I
import Button from 'material-ui/Button';
i tried with npm
and i didnt found 'Button' module @ node_module/material-ui folder

Try npm install material-ui@next --save and restart the server, it should work!

Still not working for me :(
"material-ui": "^1.0.0-beta.16",
Please help

Got it sorted by removing entry from package.json and hit
npm install material-ui

I had the same issue, uninstalled it with $ npm uninstall material-ui and re installed it $ npm i material-ui@next. The Button error is gone, now I'm missing the material-ui/Menu module.

Same here

I was able to solve this problem by running npm install material-ui@next --save and then restarting the server!

@arikaa I have try this too, Its Ok I move on to Bulma,

Cheers

In latest material-ui use the below Button types instead of "material-ui/Button';"

import FlatButton from 'material-ui/FlatButton';
import RaisedButton from 'material-ui/RaisedButton';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import IconButton from 'material-ui/IconButton';

@udithaindika You're right that they changed the types, but now i'm getting the Can't resolve 'material-ui/FloatingActionButton' error.

Changing the import doesn't always help - remember to restart your server, that solved it for me.

I fixed this error by this way.
npm install material-ui@next --save
The App code is
import React, {Component} from 'react';
import Button from 'material-ui/Button'
class App extends Component {
render(){
return (
<Button> Welcome React</Button>
);
}
}
export default App;
May help you

I'm having similar issue and nothing I do through npm is fixing it.

If I use npm install material-ui --save then RaisedButton works. However, if I use npm install material-ui@next --save (beta.22) RaisedButton does not work (Button works) and I get a bunch of other issues too.

I'm importing RaisedButton like this: import RaisedButton from 'material-ui/RaisedButton';

Anyone knows why this is happening?

@KIWI-JP perhaps material-ui will be removing the RaisedButton component some time in the future and they have already done that in beta.22?

Did you check if node_modules\material-ui\RaisedButton exists as a directory?

Same problem. No RaisedButton in "node_modules\material-ui\RaisedButton".

@djnsu Are you using the latest version of material-ui? The button should be there. I'm using 0.19.4 and i have it.

"material-ui": "^1.0.0-beta.22" from package.json. It's latest pre-release I guess.

So it seems this is the new way to do it

import Button from 'material-ui/Button';

<Button raised>
 Please Update Docs :-)
</Button>

@mikecit22

Please Update Docs :-)

Which docs?

@mbrookes my apologies this was my mistake. I was referring to these docs, material-ui when I should have been referring to these material-ui-next

Install material-ui using this command :

npm install material-ui@latest

it is working for me
npm install material-ui@next --save

my package.json has -> "material-ui": "^1.0.0-beta.33",

and in my component im using:
import Button from 'material-ui/Button';
<Button raised> working </Button>

I have the exact issue but with different components:
material-ui/CardActions
material-ui/CardContent
material-ui/CardMedia
material-ui/Tab

Reinstalling material-ui didn't help;

my package.json has -> "material-ui": "^1.0.0-beta.47"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattmiddlesworth picture mattmiddlesworth  路  3Comments

chris-hinds picture chris-hinds  路  3Comments

newoga picture newoga  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

revskill10 picture revskill10  路  3Comments