The webpack development server is failing to inject CSS

Upon reviewing the stdout output after executing the script that triggers webpack-dev-server, it seems like the scss | css files are being processed and emitted correctly. However, when visiting "localhost:8080" in devtools, the CSS is not injected by the server; almost as if the CSS doesn't even exist.

Environment: package.json

"webpack": "^4.38.0",
"webpack-cli": "^3.3.8",
"sass-loader": "^7.1.0", 
"mini-css-extract-plugin": "^0.4.1",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"css-loader": "^1.0.0",
"del": "^2.2.2",
"dialog-polyfill": "^0.5.6",
"ejs": "^2.5.7",
"ejs-loader": "^0.3.1&q...

  

package json script:

"dev": "GOOG_ATION_CREDE=app/workbox-demos-4dee.json node app/server.js",

server.js uses express + webpack middleware

const app = express();
const config = require('../webpack.config.dev.js');
const compiler = webpack(config);
app.use(
  webpackDevMiddleware(compiler, {
    publicPath: config.output.publicPa...

webpack.config.dev.js

  output: {

    filename: '[name].bundle.js',
    publicPath: '/'

  },
  devtool: 'inline-source-map',
  devServer: {
    contentBase: './',
  }...
  

css imports from express.app

import  "../styles/main.css";
import {MDCMenu} from '@material/menu';

import "../styles/camer.css";

stdout output from $npm run dev

app running http://localhost:8080 /home/rob/src/web-spch-v2/app
Hash: 771fef3df3589e3ab505
Version: webpack 4.46.0
Time: 3719ms
Built at: 01/19/2021 5:21:53 PM
                                             Asset       Size  Chunks             Chunk Names
              7719fdcabdc03146e2da973edaac2425.png   17....

Answer №1

Make sure to add the style loader before the css loader in your webpack configuration:

npm install --save-dev style-loader

Next, update your webpack.config.js file with the following loaders:

      {
        loader: "style-loader",
      },
      ,{
        loader: "css-loader",
      },
      {
        loader: "sass-loader",
        options: {
          includePaths: ['./node_modules']
        }
      }

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

Dynamic Menu Navigation (No Bootstrap Required)

My Navbar is working perfectly in the original mode but when the screen width is less than 950px, it displays the buttons stacked vertically. However, the dropdown button opens the dropdown content on the wrong side. I want the dropdown content to appear u ...

npm encountered an issue while attempting to read the JSON file

Every time I attempt to install express using npm, I encounter the same error message: Failed to parse json No data, empty input at 1:1 File: /root/.npm/inherits/2.0.1/package/package.json Failed to parse package.json data. package.json must be actual JSO ...

Ways to modify the appearance of the Sign up page on Moodle

I'm a newcomer to the world of Moodle, currently using version 2.9. I've created a unique design for my Signup page using HTML5 and CSS. How do I go about integrating this custom page? While I understand how to change the default Login page by m ...

Performing CRUD operations with mongoose and express

My express app is currently being developed with mongoose, and the goal is to integrate it with React for the front end. In my customer controller, I have outlined some CRUD operations, but there are aspects of this approach that I find unsatisfactory. W ...

Replicating Images in a Drag and Drop Layout

I am encountering an issue with my drag and drop feature, where dragging an image within the grid results in copying it instead of moving it. Below is the relevant code snippet: function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ...

What are some solutions for resolving the Cannot GET error in an express application?

While working on understanding basic express concepts, I encountered an issue. This snippet of code shows how I successfully set the route to my data JSON file and everything seems to be working fine as I can see the data. app.get('/api/v1/tours' ...

An exception is thrown by TypeScript's readline.createInterface function

My current project involves creating an electron app. I am facing an issue in the main.ts file where I have constructed a seemingly simple class with a constructor that is not running as expected. The problem arises when the call to readline.createInterfac ...

A guide on adding up all the values in a table's columns with JavaScript

I have implemented a web application feature where table rows are dynamically added using JavaScript. Each row contains a Qty Col, Unit Amount Col, and Line Total Col. Users can also remove a line after adding it to the table. In this scenario, I need t ...

Separate the two divs with some added spacing

I am facing a challenge in creating a navbar with two regions split by white space. I attempted to use float:right and justify-content: space-between, but it doesn't seem to work as expected. My goal is to have site-header-right on the right side and ...

Hash Symbol refuses to function in IFRAME

The Request.QueryString contains the file path example Temp\file#hashName.jpg protected void Page_Load(object sender, EventArgs e) { string filePath = Request.QueryString["fileName"]; iframes.Attributes.Add("src", filePath); } It then goes to the Ma ...

Using angularJS and Regular Expressions to eliminate the "+" symbols in an email address

I have been given the task of disallowing email addresses with a "+" sign from registering. As someone new to regex, my understanding is that it is better to focus on defining what constitutes a valid input rather than listing what should be excluded. I re ...

Utilizing Cowboy as the HTTP web server for Express JS

Many websites are utilizing Cowboy as the HTTP Web server and Express JS as the Web application server. They typically have their HTTP header set to Cowboy for the server, with the X-Powered-By HTTP header indicating Express. One example is This setup rai ...

What is the best way to empty the input field after a download event is completed in Node.JS?

For hours on end, I've been struggling with a persistent issue in my video downloader app. After successfully downloading a video, the input field where the URL is entered remains filled instead of clearing out. The screenshot below illustrates the p ...

What is the best way to hide a section of an image using the background of a different div?

How can I make the background of div2 cover the image in div1 when setting margin-top=-50px? Code snippet: <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> ...

Unable to perform navigation during page load in a React.js application

I attempted to navigate to a route that should redirect the user back to the homepage when postOperations isn't set in the localStorage. To save time, please review the code snippet focusing on the useEffect and the first component inside return(). im ...

Leverage JavaScript E4X to cleverly rename specific XML elements

Currently, I am using JavaScript to manipulate XML without involving the DOM in a browser context. I need assistance with creating an E4X expression that can rename a list of tags based on a given substring. The challenge is that I may not know the exact t ...

Customize the Vuetify 2.0 sass variable $heading-font-family

I'm currently trying to customize the default variable $heading-font-family in Vuetify 2.0.0-beta.0, but I'm encountering issues with this particular override. Oddly enough, I have been successful in overriding other variables such as $body-font- ...

Encountering issues with node-gyp rebuild installation on Ubuntu 20.04.2 LTS

Having trouble running a project in Visual Studio Code. Every time I try to run 'npm install,' I keep getting this npm-gyp error. I've made sure to update Node, npm, and Python to the latest versions, including installing Python 2.7, but not ...

Engage with a specific element within the Document Object Model even in the absence of a 'ref' attribute

Is there a better way to set focus on a button within a React component without using ref? The button is part of a third-party library and not immediately available upon componentDidMount. Currently, I am using setTimeout and querySelector which feels like ...

"Exploring the Power of Vue 3 Event Bus Through the Composition API

I recently set up mitt and I'm facing difficulties dispatching events to another component. The issue arises due to the absence of this in the setup() method, making it challenging to access the app instance. Here's my current approach: import A ...