I'm taking over a small react tooling project someone else had stopped maintaining. However, I can't get it to run. It's a problem with the webpack config, and I've attempted to reconstruct it at as small a size as possible but I can't get it to run.
Here's the file currently
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: './client/index.js',
output: {
path: path.join(__dirname, 'client'),
filename: 'bundle.js'
},
module: {
rules:[{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['es2015', 'react']
}
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
}],
},
resolve: { extensions: ['*', '.js', '.jsx'],
alias: { 'react-dom': '@hot-loader/react-dom' } },
}
This is the error I'm getting:
Error: Compiling RuleSet failed: Exclamation mark separated loader lists has been removed in favor of the 'use' property with arrays (at ruleSet[1].rules[1].loader: style-loader!css-loader)
Loved by many, hated by some, known to all. And still the most popular bundler in 2021. With more than 15 million weekly downloads (at the time of writing this post), there's no doubt that Webpack is still the bundler par excellence in 2021.
Out of the box, webpack won't require you to use a configuration file. However, it will assume the entry point of your project is src/index.
To solve the "Cannot find module 'webpack'" error, make sure to install webpack globally by running the npm i -g webpack command and create a symbolic link from the globally-installed package to node_modules by running the npm link webpack command. Copied! Once you run the two commands, the error should be resolved.
Webpack is first and foremost a bundler. Webpack's base functionality is to take a JavaScript file, resolve any dependencies ( require() , import , etc.), and output a bundled JavaScript file that contains all those dependencies. You can then run the bundled file without having to load those dependencies again.
The error message says that you must config with a use array (ex:
use: ['style-loader', 'css-loader']
instead of loader: "style-loader!css-loader"
. Following is an example from webpack website.
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
};
You can check the detail at https://webpack.js.org/loaders/style-loader/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With