Webpack struggles with handling css using the css-loader when trying to implement (react)-css-modules

Trying to set up webpack with react and (react)-css-modules, but encountering an issue where webpack is unable to parse the css. This is the standard configuration being used.

const webpack = require("webpack"),
merge     = require("webpack-merge"),
path      = require("path"),
CleanWebpackPlugin = require('clean-webpack-plugin'),
HtmlWebpackPlugin  = require("html-webpack-plugin");

const lint    = require("./webpack.lint");
const babel   = require("./webpack.babel");
const styles  = require("./webpack.styles");

const PATH = {
    app: path.join(__dirname, "../../src/app.js"),
    build: path.join(__dirname, "../../public"),
    src  : path.join(__dirname, "../../src"),
};

const commonConfig = merge([
    {
        entry: {
            app: PATH.app
        },
        output: {
            path: PATH.build,
            filename: "[name].[ext]"
        },
        resolve: {
            extensions: [".js", ".jsx"],
        },
        plugins: [
            new HtmlWebpackPlugin({
                template: "src/index.ejs",
                //inject: "head",
            }),
            new CleanWebpackPlugin("public", {
                verbose: true,
                root: path.resolve(__dirname, "../../")
            }),
            new webpack.HotModuleReplacementPlugin(),
        ],
    },
    lint({
        include: PATH.app,
        options: {
            plugins: ["react"],
        }
    }),
    babel({
        include: PATH.app
    }),
    styles({
        include: PATH.app
    })
]);

module.exports = (env) => {
    return commonConfig;
};

Below is the configuration for the css loader

const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = ({include, exclude = /node_modules/, options}) => ({
    module: {
        rules: [
            {
                test: /\.s?css$/,
                include,
                exclude,
                options,
                use: ExtractTextPlugin.extract({
                        use: [
                        {
                            loader: "css-loader",
                            options: {
                                importLoaders: 1,
                                modules: true,
                                localIdentName: "[name]__[local]___[hash:base64:5]" ,
                            }
                        }, 
                        "postcss-loader", 
                        "resolve-url-loader",
                        "sass-loader"],
                        fallback: "style-loader",
                    })
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin("styles.css"),
    ]
});

The javascript and jsx files are compiling correctly, however, the css is failing each time with the error message:

Module parse failed: Unexpected token (1:5) You may need an appropriate loader to handle this file type

import React, { Component } from "react";
import ReactDOM from "react-dom";

import styles from "./styles.css";

class App extends Component {
    render() {
        return (
            <div>
                <p>Hallo</p>
            </div>
        )
    }
}

ReactDOM.render(
    <App/>,
    document.getElementById("app")
);

Running node 8.7.0 and webpack 3.8.1 with the latest versions of all loaders. Any help is appreciated. Thanks!

Answer №1

The loading process encountered an error due to mistakenly passing a .js file to the css-loader. When the include path was left empty, the loader functioned properly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I struggle with managing a z-index in conjunction with an absolute position

Check out this codesandbox to see the issue where the 3 dots button is displayed over the menu. Click on the 3 dots to understand the problem. Below is the CSS code for the menu: .more-menu { position: absolute; top: 100%; z-index: 900; float: l ...

Whenever I try to retrieve data from MongoDB using Node.js, I consistently encounter a timeout error

Currently, I am in the process of developing a website using React.js for the front end, Node.js for the back end, and MongoDB as the database. Dummy data has been inserted into the database which can be viewed https://i.sstatic.net/YOzCB.png. The database ...

Understanding high traffic scenarios: Unraveling the mystery of S3 Presigned URLs

In a scenario where images are uploaded to an S3 bucket using pre-signed URLs, there may be situations of high load. In such cases, it is important to inform the user about potential delays and ask for patience. Instead of just receiving an HTTP status cod ...

Sorry, I am unable to fulfill this request as it involves rewriting copyrighted content. However, I can provide some

Whenever I attempt to execute create-react-app myapp, I keep encountering an error. I have also attempted to clear the cache using npm cache clean --force Unfortunately, this did not resolve the issue. internal/modules/cjs/loader.js:638 throw err; ^ Er ...

Exploring NodeJS: Techniques for manipulating buffer data prior to parsing it from a file

Within my NodeJS project, I have a log file structured like this: {"time":"2021-09-23T11:36:18.076Z","type":"info","message":"some message","data":{"id":123}}, {"time" ...

The API response indicates that the service is currently not accessible

I'm attempting to retrieve a report from the MOZ API, but I keep receiving this response: { "status" : "503", "error_message" : "Service Temporarily Unavailable" } This is the code I am using: function MozCall(callback) { var mozCall = ' ...

Position a single div on the left-hand side and arrange two divs on the right using display:flex

Is there a way to achieve this layout without adding another div, using only parents and 3 child elements? I had tried using height: max-content, but it didn't work as expected. .container { display: flex; flex-wrap: wrap; } .item { flex-bas ...

Styling images and text in CSS within a jQuery UI autocomplete widget

I am currently using an autocomplete widget that displays text along with images. The results I have right now are not meeting my requirements. I want to customize the appearance of my results so that the words 'test' and either 'Federico&a ...

Error in React JS: The split method cannot be applied on selectedWord

Currently, I am developing a Hangman game in React JS and encountered an error message that reads "TypeError: selectedWord.split is not a function". The section of code causing the issue is shown below: const Word = (selectedWord, correctLetters) => { ...

The 'exhaustive-deps' warning constantly insists on requiring the complete 'props' object instead of accepting individual 'props' methods as dependencies

This particular issue is regarding the eslint-plugin-react-hooks. While working in CodeSanbox with a React Sandbox, I noticed that I can use individual properties of the props object as dependencies for the useEffect hook: For instance, consider Example ...

passing data via res.redirect()

Trying to pass user_id to the profile page using res.redirect(). Below is my code from login.js: const express = require('express') const router = express.Router() let alert = require('alert') const bcrypt = require('bcrypt') ...

Experiencing double re-render with useEffect in React & Socket.io

I am currently working on developing a real-time chat application using React and Socket to familiarize myself with the fundamentals. I have encountered an issue where each message sent by a user is received twice by all other users. For navigation, I am ...

Whenever I retrieve comments for a specific playlist, I am able to see all the comments. However, I am unsure of how to access the other properties of

When retrieving the comments for a specific playlist, I am only getting the comment IDs. How can I send all the details of the comments for that playlist to the frontend? const mongoose = require('mongoose'); const Schema = mongoose.Schema; // c ...

Executing lambda functions concurrently 22 times is causing excessive latency

Upon calling lambda_B 22 times asynchronously from lambda_A, with each lambda_B call completing execution in 3 seconds, one might expect the total duration to be around 3 seconds. However, the actual time taken ranges from 16-20 seconds. Below is a snippe ...

Error: Firebase Cloud Functions reference issue with FCM

Error Encountered An error occurred with the message: ReferenceError: functions is not defined at Object. (C:\Users\CROWDE~1\AppData\Local\Temp\fbfn_9612Si4u8URDRCrr\index.js:5:21) at Module._compile (modul ...

Incorporating external .js files from a different server using node.js

Is it possible to include .js files from another server into a node.js program? I cannot simply use require('./local_file.js') to fetch files over the Internet like this: require('http://www.server.com/path/file.js'); I attempted usin ...

Develop a custom React Native module and integrate it within your mobile application

I am looking to develop a react-native module for iOS and Android that can be utilized in an application. My goal is to integrate it as a local module without having to upload it to npm. Every time I attempt to follow the steps outlined in the official d ...

Determining file extensions in nodejs is dependent on the parameter priority set for the require() function

I'm currently expanding my knowledge of node.js For instance, I experiment with: var server = require("./myserver.js"); and var server = require("./myserver"); Both of these scenarios work successfully. However, what if I introduce another file wi ...

Encountering an error while updating the node package.json file with a new dependency

I have encountered an issue with my server.js file that contains the code below. I also have a package.json file with dependencies. After adding the underscore dependency to the existing ones, I received an error when trying to run require("socket.io")(htt ...

What is the process for creating a custom hook in React.js/Next.js?

I encountered a problem while trying to create a hook from my code. Here is the snippet from the hook file: import { useRouter } from "next/router"; const useCurrentPath = () => { const { asPath, locale, defaultLocale } = use ...