I'm having trouble understanding why I'm getting an error when trying to link CSS or SCSS

 <link rel="stylesheet" type="text/css" href="scss/styles.scss">
   <link rel="stylesheet" type="text/css" href="css/styles.css">

/*webpackconfig.js*/




var path = require("path");
var HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin=require("mini-css-extract-plugin");
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');

module.exports = {
  entry:  {
    app:'./src/index.js'
  },

  output: {
    path: path.join(__dirname, "/dist"),
    publicPath:'',
    filename: "main.js"
  },


  mode: 'development',
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
   // compress: true,
   writeToDisk: true,
   open:true,
   port: 58134,
  },
  module: {
    rules: [
      
      
      {//require("expose-loader?jquery!jquery"),
        test: require.resolve("jquery"),
        loader: "expose-loader",
        options: {
          exposes: ["$", "jQuery"],
        },
      },

      { //  /\.css$/,
        test: /\.(sa|sc|c)ss$/,  
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              publicPath:'../'
            }
            
          },
          "css-loader",
        'sass-loader',
         
          /*{
            loader: "sass-loader",
            options: {
              implementation: require("sass"),
              sassOptions: {
                fiber: false,
              },
            },
          },  */
        ],
    },

    {
      test: /\.(png|svg|jpe?g|gif)$/,
      use: [
        {
          loader: "file-loader", 
          options: {
            name: '[name].[ext]',
            outputPath: "images",
          }
        }
      ]
    },

    {
      test: /\.(svg|eot|woff|woff2|ttf)$/,
      use: [
        {
          loader: "file-loader", 
          options: {
            name: '[name].[ext]',
            outputPath: "fonts",
            esModule: false,
          }
        }
      ]
    },



      {
        test: /\.html$/,
        use:[
          {
        loader: 'html-loader',
        options: {
          minimize: true,
        },
      },
    ]
      },
  
      
     
    ],
},
    
   

  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html", 
      template: "./src/index.html",
    }),
    new MiniCssExtractPlugin({filename:"css/style.css"}),

    new OptimizeCssAssetsPlugin({})
  ],
}; 
``


/*package.json*/
{
  "name": "saferny",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack serve"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^5.2.0",
    "file-loader": "^6.2.0",
    "html-loader": "^1.3.2",
    "html-webpack-plugin": "^5.3.0",
    "jquery": "^3.6.0",
    "mini-css-extract-plugin": "^1.4.0",
    "node-sass": "^5.0.0",
    "optimize-css-assets-webpack-plugin": "^5.0.4",
    "popper.js": "^1.16.1",
    "style-loader": "^2.0.0",
    "webpack": "^5.30.0",
    "webpack-cli": "^4.6.0",
    "webpack-dev-server": "^3.11.2"
  },
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.15.3",
    "@laylazi/bootstrap-rtl-scss": "^4.6.0-1",
    "bootstrap": "^4.6.0",
    "bootstrap-v4-rtl": "^4.6.0-2",
    "expose-loader": "^2.0.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "jquery.animate": "^1.8.9",
    "resolve-url-loader": "^3.1.3",
    "sass": "^1.32.12",
    "sass-loader": "^11.0.1"
  }
}
import './scss/styles.scss';
import './css/style.css';
//import '../node_modules/@laylazi/bootstrap-rtl-scss/scss/bootstrap-rtl.scss';
import 'bootstrap-v4-rtl/dist/css/bootstrap.min.css';
import 'jquery/dist/jquery.min';
import 'popper.js/dist/popper.min';
import 'bootstrap/dist/js/bootstrap.min.js';
import '@fortawesome/fontawesome-free/js/all.min';
import 'jquery.animate';
import 'jquery';

ERROR in Error: Child compilation failed: No template for dependency: CssDependency CodeGenerationError: No template for dependency: CssDependency

  • Compilation.js:2623 [safernyy]/[webpack]/lib/Compilation.js:2623:18

  • Cache.js:91 [safernyy]/[webpack]/lib/Cache.js:91:34

  • ...

2 ERRORS in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details) webpack 5.30.0 compiled with 7 errors in 5684 ms i 「wdm」: Failed to compile.

Answer №1

To utilize MiniCssExtractPlugin, you must have the CSS imported within the JavaScript file. If your stylesheets are linked in the HTML, you will need to use the (unfortunately unmaintained) extract-loader. Make sure to set esModule: false, or else extract-loader will not work properly.

            {
                test: /\.css$/,
                use: [
                    {
                        loader: "file-loader",
                        options: {
                            name: "[name].css",
                            outputPath: "css",
                            esModule: false,
                        }
                    },
                    {
                        loader: "extract-loader",
                    },
                    {
                        loader: "css-loader",
                        options: {
                            esModule: false,
                        }
                    }
                ]
            },

This setup works for me with

<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65001d111704061148090a0401001725504b544b55">[email protected]</a>
,
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f5fafff6befffcf2f7f6e1d3a5bda1bda3">[email protected]</a>
, and
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="106775726071737b50253e25233e20">[email protected]</a>
.

Answer №2

Resolved the error by updating Node to version >=18. Here is the updated webpack configuration:

{
            test: /\.(scss|css)$/,
            use: [
                {
                    loader: MiniCssExtractPlugin.loader,
                },
                {
                    loader: "css-loader",
                    options: {
                        sourceMap: true,
                        modules: false,
                    },
                },
                {
                    loader: "postcss-loader",
                    options: {
                        postcssOptions: {
                            plugins: ["autoprefixer"],
                        },
                    },
                },
                { loader: "sass-loader", options: { sourceMap: true } },
            ],
        },

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

CORS policy is preventing all development requests from going through

In my setup, I have a Rails API paired with a React client side. Everything has been running smoothly for some time now, but recently I encountered an error while working on it: Access to XMLHttpRequest at 'http://localhost:3000/api/v1/user/authed&apo ...

Acquire data from HTML using Python

Just starting out with Python so any help would be appreciated. I'm working on a webpage and need to retrieve the value from a specific tag. Is there a Python library that can assist me with this task? Thanks in advance. ...

"Exploring the process of utilizing AngularJS to open a .docx file in a new template

When attempting to open a .jpeg or .pdf file in a new template using an iframe, it was successful. However, the same approach failed when trying to open a .docx file. How can this issue be resolved? Angularjs code: $scope.openTemplate = function ($fpath ...

Tips for determining the height of the entire webpage using jQuery

I attempted the following code: $(window).height(); $("#content").height(); However, it did not provide an accurate value. ...

Using passport.js to create a user and verify their identity

I'm currently facing an issue with saving and registering a user simultaneously. Below is my current schema: const userSchema = new mongoose.Schema({ username: String, password: String, firstName: String, lastName: String, player: { type: Boolean, ...

Updating a URL in an HTML form with JavaScript

Currently, I am faced with the task of manipulating a variable's value in a JS file within a function that is responsible for dynamically updating values in an HTML table without necessitating a full website reload. The function code snippet appears b ...

Efficient techniques for developing lazy-loading ajax services

What are some efficient ways to create lazy ajax services in angular-js? For instance, I need a resource that returns a promise such as: angular.module('MyModule',[]) .factory('myService', function() { return { getData: fun ...

Step-by-step guide on achieving 100% height for a child element within a parent using Flexbox

Currently facing an issue where trying to make a child element take up 100% of the remaining height of its parent container causes the child's height to go beyond the boundaries of the parent. HTML .container { height: 340px; /* background-i ...

Unable to create a new collection in Firebase Firestore

I encountered an issue while trying to add a collection in Firebase Firestore using the function .collection(doc).set. Despite finding the new user in authentication in Firebase, the collection was not created and the console displayed an error message. ...

CRITICAL ERROR: CALL_AND_RETRY_LAST Memory allocation failed - JavaScript heap exhausted

I am experiencing issues when trying to search using npm: npm search material However, I keep getting this error message: npm WARN Building the local index for the first time, please be patient FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaSc ...

Redux - The same reducers, containers, and components are yielding varying outcomes

update: Issue resolved by connecting a different variable to the mapStateToProps. I'm encountering some challenges with my react-redux application and I'm struggling to pinpoint the error in my setup. You can access the source code here. The f ...

Tips for fixing a shader issue with a custom hover state shader on an image component in a React project utilizing react-three-fiber

I am currently working on implementing an image component with a hover effect using shaders in react-three-fiber. The shader I'm using was originally created by TheFrost and it can be found at https://codepen.io/frost084/full/OKZNRm. However, I am e ...

jQuery is failing to properly render dynamic content data identifiers

Need help with a dynamic HTML div <a data-id="17" onclick="getcustomer();"> <div class="note note-success"> <h4 class="block">A</h4> <p>Email : <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Issue with Highcharts: Border of stacking bar chart not visible on the right side

When creating a stacking bar chart, I noticed that the rightmost 'box' does not have a border drawn on the right side. Is there a setting or option in Highcharts that can be used to ensure the white border line is drawn around the 75% box in the ...

When the content div is clicked within the overlay div, the popup will also close

I want to design a pop-up that features a container with a black background and some opacity, where the content of the popup is placed inside. Here's what I have in mind: <button (click)="showPopup = !showPopup">Open popup</button& ...

How to fix the issue of not being able to pass arguments to the mutate function in react-query when using typescript

Currently, I am exploring the use of react-query and axios to make a post request to the backend in order to register a user. However, I am encountering an error when attempting to trigger the mutation with arguments by clicking on the button. import React ...

Updating strings in multiple documents in MongoDB is easily achievable using the powerful combination of Mongoose, Express, and Node.js. By utilizing the

In my 'content' collection, there are numerous documents with similar structures: {"_id":"5e01043e9fde7f33b8133b2d", "name":"home", "documentTypeId":"5df01430600e2258382ffb9c", "parentContnetId":"", "active":true, "published":false, "Url":"/home ...

Using Three.js to display a CSS3D-rendered DIV in full-screen mode

After extensively experimenting with the three.js library, I was able to establish two distinct scenes – one canvas-rendered and the other css3d-rendered – both displayed using the same perspective camera. Note: Despite my efforts, I am constrained to ...

having trouble with displaying the results on the webpage

I am facing an issue while trying to display the data fetched from the database: {"results": ["USA", "Canada"]} {"message":"Could not find any countries."} //else An error was encountered in the console: Uncaught TypeError: Cannot read property 'l ...

I'm encountering an issue with the preflight request failing the access control check. It seems to be related to not having an HTTP ok status, and I've double-checked everything to make sure I imported

I've encountered an error message stating, "Response to preflight request doesn't pass access control check: It does not have HTTP ok status." Any suggestions on what might be causing this issue? Here is the backend code snippet: app.js app.del ...