Reputation: 21
I am trying to use scss modules in my React app but getting error.
I configured my react app using webpack, now when I went on to configure scss modules, i got this error. The webpack build is failing, but when I remove the module.scss rule it works fine with only the .scss rule
ERROR in ./src/components/Button/Button.module.scss (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!./node_modules/sass-loader/dist/cjs.js!./node_modules/style-loader/dist/cjs.js!./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/components/Button/Button.module.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
expected "{".
╷
2 │ import API from "!../../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js";
Below is my webpack.config.js file:
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./src/index.tsx",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
clean: true,
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.module\.scss$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: true,
sourceMap: true,
},
},
{
loader: "sass-loader",
}
],
exclude: "/node_modules/",
},
{
test: /\.scss$/,
exclude: "/.module.scss$/",
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(js|jsx)$/,
use: { loader: "babel-loader" },
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: "./public/index.html",
}),
],
};
Upvotes: 1
Views: 12