Solving an Error in ReactJS/Material-UI
This is an important error to look out for. Luckily, it's pretty easy to resolve — it stems from an easily made mistake.
Join the DZone community and get the full member experience.
Join For FreeI’ve been playing around with ReactJS and the Material-UI library and I recently ran into this error while trying to follow one of the examples from the demo application:
ERROR in ./src/app/modules/Foo.js
Module not found: Error: Cannot resolve module 'material-ui/lib/Subheader' in /Users/markneedham/neo/reactjs-test/src/app/modules
@ ./src/app/modules/Foo.js 13:17-53
webpack: Failed to compile.
This was the component code:
import React from 'react'
import Subheader from 'material-ui/lib/Subheader'
export default React.createClass({
render() {
return <div>
<Subheader>Some Text</Subheader>
</div>
}
})
That code is then rendered like this:
import Foo from './modules/Foo' render(Foo, document.getElementById("app"))
I came across this post on Stack Overflow that seemed to describe a similar issue. It led me to realize that I was actually on the wrong version of the documentation. I’m using version 0.16.7 but the demo I copied from is for version 0.15.0-alpha.1!
This is the component code that we actually want:
import React from 'react'
import Subheader from 'material-ui/Subheader'
export default React.createClass({
render() {
return <div>
<Subheader>Some Text</Subheader>
</div>
}
})
And that’s all I had to change. There are several other components that you’ll see the same error for. It looks like the change was made between the 0.14.x and 0.15.x series of the library.
Published at DZone with permission of Mark Needham, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Demystifying SPF Record Limitations
-
Java String Templates Today
-
Microservices: Quarkus vs Spring Boot
-
Automated Multi-Repo IBM App Connect Enterprise BAR Builds
Comments