Encountering a runtime issue while attempting to utilize CSS modules in conjunction with React and Snowpack

I am facing an issue while attempting to set up css modules with react and snowpack. Below are the steps to reproduce the problem:

"snowpack": "^2.17.0",

"@snowpack/plugin-sass": "^1.1.1",

Start by creating a new app using npx

npx create-snowpack-app snowpack --template @snowpack/app-template-react-typescript

npm install @snowpack/plugin-sass --save-dev

Add a sass file app.sass

.test
  width: 30px
  height: 30px
  background: red

App.tsx

import styles from './app.sass'

<div className={styles.test}/>

Snowpack devOptions

port: 8005,
open: 'none',
bundle: false,
out: 'dist'

Snowpack plugins

'@snowpack/plugin-react-refresh',
'@snowpack/plugin-dotenv',
'@snowpack/plugin-typescript',
'@snowpack/plugin-webpack',
'@snowpack/plugin-sass',

Run snowpack dev

npm start => snowpack dev

Error

SyntaxError: The requested module './app.css.proxy.js' does not provide an export named 'default'

https://i.sstatic.net/rGd7V.png

Answer №1

To fix the issue, you should change the name of `app.sass` to `app.module.sass`

CSS Modules are supported in Snowpack by following the naming convention of `[name].module.css`. These CSS Modules operate similarly to regular CSS imports, but they include a special default styles export that connects your original class names to unique identifiers.

Learn more about importing CSS Modules in Snowpack here

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

Using Laravel to connect custom fonts

After previously discussing and experimenting with linking custom font files in Laravel, I encountered an issue where the fonts were not displaying correctly on my website. Due to Laravel's router, directly linking to font files in CSS was posing a ch ...

A dual row navigation layout with the second row featuring equally distributed elements in a neat and organized manner

Looking to create a responsive collapsible navigation with two rows. The first row should contain the logo and language selector, while the second row should have the main links: | | | ...

Tips for modifying button styles with CSS

I am facing an issue with a submit button on my form. The button currently has an image, which is unnecessary as the same image is used elsewhere on the page. I believe there might be a parent-child element problem preventing me from making the necessary c ...

Using classes to override CSS

I've been going through the Material UI Overrides documentation in an attempt to customize the color of each radio button, but I'm having trouble grasping it conceptually. If I start with Material UI's default setup for radio buttons, how ca ...

Adding a command to open a new browser tab using JavaScript code can easily be accomplished by following these steps. By using Terminal, you can quickly and efficiently implement this feature

I'm new to coding and trying to create a terminal simulation. You can check out my code here: https://codepen.io/isdampe/pen/YpgOYr. Command: var coreCmds = { "clear": clear }; Answer (to clear the screen): function clear(argv, argc ...

The logo and text appear to be out of place and not properly

My current project involves creating an email signature that is easily transferable to email programs like Outlook or Gmail. You can access the website for this project here: After pasting the signature into Gmail, it displays correctly. However, when pas ...

How to create a faded effect on a background image within a bootstrap carousel

Can anyone help me figure out how to make my images darker in order to enhance the readability of the text on them? I am using a bootstrap carousel theme and struggling to achieve the desired darkness. Opacity adjustments are affecting the transparency of ...

What could be causing the divs to not display as inline-block elements in the HTML section?

Currently, I am utilizing an Html5 template. The template is a onepager and there is a specific section that I would like to include for displaying 'business hours'. Ideally, this section should list three days with their corresponding times on e ...

Center align the list items on mobile using flex in bootstrap 4

At the top of my page, I have a div called header_full_width. This div spans 100% of the width of the page. Within this div, there is a container, a row, a col-md-12 div, and an unordered list with list items and links. My issue is that on mobile devices, ...

Creating a dropdown menu that seamlessly populates elements without any empty spaces

My team at the company is using a menu created by another developer. I recently added a dropdown selection to the first item on the menu, but I've run into an issue where the dropdown box does not fully fill the item, and I can't seem to fix it. ...

What is the method for adjusting the height of a select2 box in a bootstrap environment?

Is it possible to adjust the height of the field on a website without access to the code? I found an example on this site: toster.ru/q/193633 ...

Generate a new div element dynamicaly after every 10 elements are added

I am facing the following scenario: I need to dynamically add an UNKNOWN number of checkboxes to a layout component, arranged in columns with 10 checkboxes per layout item. Although I have successfully added all the checkboxes to a single div element, I ...

fancybox thumbs will never function properly

I recently made the switch from using PrettyPhoto to FancyBox for my gallery, which utilizes Isotope for filtering and animations. However, I am encountering an issue where the images appear but the thumbnails are missing. In the developer tools, there is ...

Utilizing unique background images tailored to different screen resolutions

In order to enhance the user experience on my website, I am looking to implement a feature that dynamically changes the background images based on the user's screen resolution. My plan is to use a small snippet of JavaScript within the <head> s ...

The .AppendChild() method does not appear to be working as expected following the completion of

Encountering a peculiar problem here. The scripts run smoothly, but the content doesn't display on screen until I "inspect element" and then close the inspector window or zoom in/out. It's not an issue with the "display" CSS property because even ...

The <hr> line in Bootstrap is placed in a peculiar manner

Take a look at the fiddle here: https://jsfiddle.net/mv5ut6sw/ On my website, I have a set of links displayed in a <div> at the top. To visually separate these links from the rest of the page, I want to add horizontal lines above and below the conta ...

Achieving Perfect Alignment in HTML Tables

I have created a simple HTML table and I am trying to center it vertically in the middle of the page based on the user's device height. So far, I have tried adding a div with 100% height and width, positioning the table at 50% from the top and left, b ...

Exploring the differences between two string variables in JavaScript

While attempting to compare two strings using JavaScript, I encountered the following code: var statuss = document.getElementById("status").innerHTML; //alert(statuss); var s =statuss.toString(); var ss= "Active"; if (s === "Active"){ aler ...

tips on customizing buttons within form groups

I have set up two separate form-groups: My goal is to click on each button within each group and toggle its style from grey to green, and vice versa. However, when I click on a button, all buttons within the group turn grey except for the one that was cli ...

Creating animated keyframes with JavaScript and Jquery within a React environment

Currently, I am developing an animated feature within a react project. Specifically, the animation involves numerous dynamic bubbles. For each bubble, I require a rapid growth and shrink effect. Here is a snippet of how my css animation is structured: @k ...