1

I installed material-UI and I'm trying to import a button and it's throwing me an error.

The code (inside my index.js file in client folder) :

import React, { Component } from 'react'
import { render } from 'react-dom'
import { Launcher } from '../../src'
import messageHistory from './messageHistory';
import Highlight from "react-highlight.js";
import './../assets/styles'
import io from 'socket.io-client';
import ReactDOM from 'react-dom';
import Button from '@material-ui/core/Button';

error:

 ERROR  in ../~/@material-ui/core/Button/Button.js
 Module not found: Error: Can't resolve 'react' in `'C:\Users\dale.grant\Desktop\hyberchat-chat-service\node_modules\@material-ui\core\Button'`

And it says this about 11 times just with different parts such as Button/ripple.js

One thing I've noticed is I have a package-json and a package-lock.json for this client side and for my server side, and the material-ui is inside the package-lock.json for my server side? Anyway, I've tried deleting the node-modules etc a few times and restarting them.

Not sure if I've missed something? I created the app from 'react-chat-window' not sure if that is 'create-react-app' but I think it is?

I also tried installing material-ui while inside my client folder too.

The client is run by web-pack and server just normal node.

package.json: "dependencies": { "emoji-js": "3.2.2", "gh-pages": "^1.0.0", "material-ui": "^0.20.2", "prop-types": "15.5.10", "react": "^16.5.2", "react-dom": "^16.5.2", "react-highlight.js": "1.0.5", "socket.io-client": "2.0.3"

also the client package.json:

"body-parser": "^1.18.3",
"dialogflow": "^0.7.0",
"express": "^4.16.3",
"nodemon": "^1.18.4",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"socket.io": "^2.1.1"

thanks.

2 Answers 2

3

Please make sure that you've installed material-ui dependency

You can install it by running npm install @material-ui/core command

After that you can use it in your project

Sign up to request clarification or add additional context in comments.

2 Comments

So I did install it but did I not do it as dependency? whats the difference? also I have a client and a server both with their own package.json and package-lock.json - does this mean I install it in the main project folder, one of these two or both of them?
It should be installed in the client part of a project since you will be using this library for rendering a button. You are missing the material-ui on client side, just install it and it is going to work.
0

Please confirm that react dependency is added in package.json.

1 Comment

Added it ! Please see above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.