MDIT
MDIT

Reputation: 1548

Webpack et React 16: Failed to compile. ./node_modules/style-loader/lib/addStyles.js

I'm building an App using React 16.4.2, unfortunately I've got this error message after installing Bootstrap 4 (via npm: np install bootstrap):

Failed to compile.

./node_modules/style-loader/lib/addStyles.js

Module build failed: Error: ENOENT: no such file or directory, open 'C:\Users\open\Desktop\react-app\contactmanager\node_modules\style-loader\lib\addStyles.js'

This is my App.js file (where I import bootstrap):

import React, { Component } from "react";
import Contact from "./component/Contact";
import Header from "./component/Header";

import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";

class App extends Component {
  render() {
    return (
      <div className="App">
        <Header />
        <Contact name="My Name" email="[email protected]" phone="+XXX XXX XXX" />
      </div>
    );
  }
}

export default App;

By the way, I only have two components: Header and Contact.

Any Idea Please?

Thank You.

Upvotes: 1

Views: 3907

Answers (2)

jspru
jspru

Reputation: 1238

I ran into the same issue but deleting node_modules and reinstalling did not help.

'style-loader' was still missing and I have to manually install it via 'npm install style-loader', then stop and restart the React application.

I used create-react-app, with the following versions:

"bootstrap": "^4.1.3", "react": "^16.6.3", "react-dom": "^16.6.3", "react-scripts": "2.1.1"

Upvotes: 2

Tholle
Tholle

Reputation: 112927

It looks like your style-loader installation is corrupt. It will most likely be resolved if you just remove your dependencies and install them from scratch.

rm -rf ./node_modules && npm install

Upvotes: 10

Related Questions