"What is the significance of the .default property in scss modules when used with typescript

When dealing with scss modules in a TypeScript environment, my modules are saved within a property named default.

Button-styles.scss

.button {
  background-color: black;
}

index.tsx

import * as React from 'react';
import * as styles from './Button-styles.module.scss';

console.log(styles);

export const Button = () => (
  <button className={styles.default.button}>Hello</button>
);

Console Log Output

Module {__esModule: true, default: {button: "_2t432kRILm79F3WhLGdN6N"}, Symbol(Symbol.toStringTag): "Module"}

Why does this happen? It's causing issues for generating types with typed-scss-modules.

EDIT:

Here is the Storybook configuration:

const path = require('path');

module.exports = {
  stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
  webpackFinal: async (config) => {
    config.module.rules.push({
      test: /\.scss$/,
      use: ['style-loader', 'css-loader?modules=true', 'sass-loader'],
      include: path.resolve(__dirname, '../'),
    });
    return config;
  },
};

Answer №1

To make necessary modifications, you must update your css-loader rule to include the "esModule": false parameter, as shown below:

{
  loader: 'css-loader',
  options: {
    esModule: false,
  }
},
{
  loader: 'sass-loader',
}

This adjustment guarantees that import statements will only return the string value.

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

Custom stylesheet for individual users?

On my website, users can pick a template for their webpage. After selecting a template, I would like them to have the ability to customize certain styles like the font color. Is there a way to achieve this? I was thinking about saving the user's cus ...

what are some tips for making Material-Ui Chips editable?

I am striving to achieve a similar result like the 4th Example using ReactJS and Material-ui. I have created something different by overlapping two fields, one being a normal input shown on focus for text editing and the other a chips container displayed ...

The listbox is experiencing display issues when viewed in the Chrome browser

Hey, I'm having an issue with adding background color and border to my Listbox. There seems to be a white strip on the right and bottom of the options. The layout rearranges properly when hovering over each item. <select> <option>H ...

What is the best way to prioritize theme styles in Material UI over the inherited font CSS on a webpage?

I am in the process of developing a browser extension using React with MUI. This extension will be injected into the DOM of a specific page, which includes a CSS file that contains a rule targeting h6 elements: h6 { font: inherit; } Despite explicitly s ...

What is the best method to avoid consecutive URLs in React Router?

Imagine that you repeatedly click on something like <Link to="/">{...}</Link>. If the "/") pathname is pushed onto history.location multiple times in a row, how can you avoid this repetition? Is it detrimental to the user experience? ...

Struggling with Material-UI DataGrid's sorting issue in numeric columns

I am currently working on a project involving the DataGrid Component from Material-UI. While data can be displayed, I am encountering issues with the built-in sorting feature. When attempting to sort in ascending or descending order, it seems to be priorit ...

What is the best way to center this menu on the web page?

Is there a way to center this menu on the web page for better alignment? Any suggestions on improving the code are welcome. Thank you in advance. Edit: Also, how can I modify the hover effect to change the background color to green and make it expand full ...

Height of the image is being boosted while the width remains consistent

When working on a responsive page layout, I encountered an issue with increasing the height of an image while keeping the width constant. Modifying the width of the image reflects changes, but adjusting the height does not seem to make any difference. I t ...

Can anyone provide guidance on setting up a TypeScript service worker in Vue 3 using the vite-plugin-pwa extension?

I am looking to develop a single-page application that can be accessed offline. To achieve this, I have decided to implement a PWA Service Worker in my Vue webapp using TypeScript and Workbox. I found useful examples and guidance on how to do this at . Ho ...

Select a single option from the group to include in the array

I'm currently developing a new soccer betting application. My goal is to allow users to choose the result of a match - whether it's a win, loss, or draw - and then save that selection in a list of chosen bets. https://i.stack.imgur.com/hO3uV.png ...

Is there a way to determine if a user has the ability to navigate forward in Next.js?

I am faced with a challenge of determining whether a user can navigate forward on a webpage. My goal is to have two buttons - one to go back and another to go forward, with the forward button disabled when navigation is not possible. For the back button f ...

Utilizing Multer for MERN File Upload

For my project, I am working on creating a Pinterest-like platform where users can upload images. However, I am facing an issue with fetching files from the frontend to the backend using axios. Below is the code for the server: After testing various solut ...

Leverage glob patterns within TypeScript declaration files

Utilizing the file-loader webpack plugin allows for the conversion of media imports into their URLs. For example, in import src from './image.png', the variable src is treated as a string. To inform TypeScript about this behavior, one can create ...

The arrangement of my inline-block divs is oddly meandering in a zig-zag pattern

I am attempting to visualize basic commands and their arguments in HTML. Here is the expected output: https://i.stack.imgur.com/MTxbV.png However, the actual output looks like this: https://i.stack.imgur.com/biPFw.png This is the code I utilized: ht ...

What could be causing the malfunction of my token rotation feature in nextAuth?

I am developing a web application that involves working with an external API alongside my team member. We are making API requests using Next.js. I have implemented nextAuth for authentication, but I am facing issues with token rotation. After successful lo ...

Exclusive JQuery Mobile Styles

Although I enjoy using JQuery Mobile, I'm facing compatibility issues with my custom Javascript on the page. Despite everything functioning correctly without JQuery Mobile, adding the library causes problems that I've been unable to resolve. Ess ...

Within my React project, I have incorporated a popover component from Material UI. However, I have encountered an issue where the popover does not appear when hovering over the icon

I'm struggling with a certain issue. I have created a popover component that should display when the user hovers over an 'i' icon and disappear when they move away from it. However, it seems like the open and close methods are being continuo ...

Trouble with CSS display in Internet Explorer 8

My website located at this link is working perfectly in IE 10 and IE 11, however, any version lower than that is causing the content to be displayed on the far left of the screen instead of centering it. I have tried tweaking the CSS but can't seem to ...

Using PHP Hover should apply CSS styles exclusively to the specified element

I have a piece of PHP code that displays cards. What I need: When a user hovers over the entire element, I want to make the title bolder, move the arrow to the left, and zoom in on the image of that particular hovered element. <div class="posti-class ...

Is it possible to create a resizable menu without distorting its appearance?

After setting up a menu on my website, I noticed that when resizing the window, it spills over into other divs on the same line. Despite trying multiple solutions, I have been unsuccessful in resolving this issue. The navigation for the menu is contained w ...