Home > other >  Module not found, problem can not resolve style-loader
Module not found, problem can not resolve style-loader

Time:10-21

I am getting this error ERROR in ./src/client/index.js Module not found: Error: Can't resolve 'style-loader' This is my index.js even though I have specified the path correctly

import { checkForName } from './js/nameChecker'
import { handleSubmit } from './js/formHandler'


import './styles/base.scss'
import './styles/footer.scss'
import './styles/form.scss'
import './styles/header.scss'
import './styles/resets.scss'

console.log(checkForName);

alert("I EXIST")
console.log("CHANGE!!");

And this is my config file, I have tried npm install style-loader css-loader --save but still isn't working

const path = require('path')
const webpack = require('webpack')
const HtmlWebPackPlugin = require("html-webpack-plugin")
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

module.exports = {
    entry: './src/client/index.js',
    mode: 'development',
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: '/\.js$/',
                exclude: /node_modules/,
                loader: "babel-loader"
            },
            {
                test: /\.scss$/,
                use: [ 'style-loader', 'css-loader', 'sass-loader' ]
            }
        ]
    },
    plugins: [
        new HtmlWebPackPlugin({
            template: "./src/client/views/index.html",
            filename: "./index.html",
        }),
        new CleanWebpackPlugin({
            // Simulate the removal of files
            dry: true,
            // Write Logs to Console
            verbose: true,
            // Automatically remove all unused webpack assets on rebuild
            cleanStaleWebpackAssets: true,
            protectWebpackAssets: false
        })
    ]
}

this is JSON code

{
  "name": "example-project",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node src/server/index.js",
    "build-prod": "webpack --config webpack.prod.js",
    "build-dev": "webpack  --config webpack.dev.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "express": "^4.17.1",
    "webpack": "^4.35.3",
    "webpack-cli": "^3.3.5"
  },
  "devDependencies": {
    "@babel/core": "^7.10.2",
    "@babel/preset-env": "^7.10.2",
    "babel-loader": "^8.1.0",
    "clean-webpack-plugin": "^3.0.0",
    "css-loader": "^3.6.0",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.14.1",
    "sass-loader": "^7.3.1",
    "style-loader": "^0.23.1",
    "webpack-dev-server": "^3.7.2"
  }
}

Thanks in advance!

CodePudding user response:

I used your configurations and managed to build after updating the versions of node-sass and sass-loader. Could you try these versions (update in your package.json and run npm install)

    "node-sass": "^7.0.3",
    "sass-loader": "10.3.1",
  • Related