Enable the generation of scss.d.ts files with Next.js

I'm currently working on a project that requires the generation of .d.ts files for the scss it produces. Instead of manually creating these files, I have integrated css-modules-typescript-loader with Storybook to automate this process.

However, I am facing difficulties in getting the same setup to work in nextjs. Despite modifying next.config.js as shown below:

webpack: function (config, options) {
    const { dir, defaultLoaders } = options
    config.module.rules.push({
      test: /\.md$/,
      use: 'markdown-loader'
    })
    config.module.rules.push({
      test: /\.module.scss$/,
      include: [dir],
      exclude: /node_modules/,
      use: [
        defaultLoaders.babel,
        {
          loader: 'css-modules-typescript-loader',
          options: {  mode: process.env.CI ? 'verify' : 'emit' }
        }
      ]
    })
    
    return config
  },

When implementing this, it interferes with the existing processing done by next which causes issues. My main goal is only to generate the d.ts files without affecting any other functionalities provided by nextjs. Is there a way to achieve this?

Additional attempts using external packages like typed-scss-modules were made, but they do not seem to support specifying namespaces used in our sass files defined in next.config.js (referenced below):

sassOptions: {
    outputStyle: 'expanded',
    indentWidth: 4,
    prependData: `
        @use '@themes/vars' as vars;
        @use '@themes/breakpoints' as bp;
      `
  }

Answer №1

Although I have never used css-modules-typescript-loader, I did utilize typed-less-module in one of my projects to create typing files. You can try using Typed SCSS Module which works in a similar way.

// You could add something like this to your package.json
"typegen:scss": "tsm ./src --exportType default",

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

What is the syntax for assigning a public variable within a TypeScript function?

I am finding it challenging to assign a value to a public variable within another function. I seem to be stuck. export class MyClass{ myVar = false; myFunction(){ Module.anotherFunction(){ this.myVar = true; } } } ...

Error in Typescript: The identifier 'Proxy' is unknown

I'm trying to create a new variable using the Proxy type from the ES6 specification: myProxy: Proxy; However, I'm encountering the following error: Cannot find name 'Proxy'. Can anyone point me in the right direction to resolve th ...

What is the procedure for enabling S3 images or objects to be downloaded exclusively through website requests using pre-signed URLs?

I am facing a serious issue with my AWS S3 bucket setup. I have been using the aws-sdk javascript to upload files to the bucket and providing object links for downloading on my Next.js website. However, I recently realized that the bucket permissions are s ...

Angular form requests can utilize the Spring Security Jwt Token to allow all options methods

Despite checking numerous sources online, I am facing a persistent issue with my Angular application. The problem arises when using HttpClient along with an Angular interceptor to set headers for authentication in my Java Rest API using JWT tokens. The int ...

Creating a parameterized default route in Angular 2

These are the routes I've set up: import {RouteDefinition} from '@angular/router-deprecated'; import {HomeComponent} from './home/home.component'; import {TodolistComponent} from './todolist/todolist.component'; import { ...

Every time I clear the information, it seems to be instantly replaced with new data. How can I prevent it from constantly refilling?

When I press the remove button on my application, it successfully deletes the data in a field. However, it also automatically adds new data to the field which was not intended. I am seeking assistance on how to keep those fields empty after removing the ...

The .ts source file is mysteriously missing from the development tool's view after being deployed

When I work locally, I can see the .ts source files, but once I deploy them, they are not visible in any environment. Despite setting my sourcemap to true and configuring browserTargets for serve, it still doesn't work. Can someone help with this issu ...

Retrieve both the name and id as values in an angular select dropdown

<select (change)="select($event.target.value)" [ngModel]="gen" class="border border-gray-200 bg-white h-10 pl-6 pr-40 rounded-lg text-sm focus:outline-none appearance-none block cursor-pointer" id="gend ...

Creating a Typescript mixin function that accepts a generic type from the main class

I am working with the code snippet shown below: // Types found on https://stackoverflow.com/a/55468194 type Constructor<T = {}> = new (...args: any[]) => T; /* turns A | B | C into A & B & C */ type UnionToIntersection<U> = (U extend ...

Using a component again with variations in the input data

I'm looking to reuse a card component to display different types of data, but the @Input() properties are for different objects (articles and events). Parent HTML: <card-component [headline]="Articles" [content]="art ...

Typescript challenge: Implementing a route render attribute in React with TypeScript

My component has props named project which are passed through a Link to a Route. Here's how it looks (the project object goes in the state extended property): <Link to={{ pathname: path, state: { project, }, }} key={project. ...

Eliminate apostrophes in a string by using regular expressions

Can someone help me with this word What is The Answer? I need to eliminate the space and apostrophe '. To remove spaces, should I use this method: data.text.replace(/ +/g, ""). But how can I remove the apostrophe? ...

Guide to seamlessly incorporate a HTML template into your Angular 7 project

I'm currently in the process of integrating an HTML template into my Angular 7 project, and unfortunately, it does not seem to be functioning as expected. To start off, I have placed the template files under assets/template/.. and included the necess ...

Customizable TypeScript interface with built-in default key value types that can be easily extended

One common pattern that arises frequently in my projects involves fetching values and updating the UI based on the 'requestStatus' and other associated values. type RequestStatus = | 'pending' | 'requesting' | 'succ ...

Perplexed by the implementation of "require(...)" in TypeScript

After reading several blog posts, my understanding of TypeScript modules remains confusing. I have worked with three different modules (all installed via npm) and encountered varying behavior: (1) Importing and using Angular 2 from npm required me to add ...

VSCode displaying HTML errors within a .ts file

There is a strange issue with some of my .ts files showing errors that are typically found in HTML files. For example, I am seeing "Can't bind to 'ngClass' since it isn't a known property of 'div'" appearing over an import in ...

What is the best way to display my 'React Loading Spinner' component at the center of my view?

Whenever I use the Loading as my parent component for the Layout component, it always shows up in the center of the page instead of within my view. How can I adjust its positioning? ...

What is the best method for retrieving an item from localstorage?

Seeking advice on how to retrieve an item from local storage in next.js without causing a page rerender. Here is the code snippet I am currently using: import { ThemeProvider } from "@material-ui/core"; import { FC, useEffect, useState } from "react"; i ...

Issues with downloading the word file from Azure blob storage in the Next.js application have led to corruption

I stored the word file on azure blob storage. Now, I am attempting to retrieve the word file in a next.js application. The file is successfully downloaded, however, when trying to open it in MS Word, an error message is displayed: https://i.stack.imgur.c ...

Display real-time cryptocurrency price data with React component

Looking for a React component that can display real-time cryptocurrency data fetched from a decentralized exchange. I need the ability to filter by price, market cap, or percentage. I've noticed that the same exact component is used on various platfor ...