Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module '@material-ui/core'

I had a problem with importing "@material-ui/core" to my react/typescript/webpack app. Always when I ran

webpack --config webpack.config.js

it failed with error

Cannot find module '@material-ui/core'

The same error was also underlined in the Visual Studio Code.

My index.tsx looked like this

import React from "react";
import ReactDOM from 'react-dom';
import { Button } from "@material-ui/core";

function App() {
    return <Button>Hi dudes</Button>
}
ReactDOM.render(<App />, document.getElementById("root"));
like image 704
Hourglasser Avatar asked Aug 28 '26 15:08

Hourglasser


2 Answers

yarn add @material-ui/core or npm i @material-ui/core fixed the issue for me.

like image 70
Kundan Avatar answered Aug 30 '26 05:08

Kundan


Set tsconfig.json as below

{
    "compilerOptions": {
        "outDir": "./dist",
        "target": "es5",
        "lib": ["es6", "dom"],
        "module": "ES6",
        "jsx": "react",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "allowSyntheticDefaultImports": true,
        "allowJs": true
    },
    "exclude": [
        "dist"
    ]
}

allowJs made it importable and other fixed webpack build.

like image 21
Hourglasser Avatar answered Aug 30 '26 04:08

Hourglasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!