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

Filter array to only include the most recent items with unique names (javascript)

I'm trying to retrieve the most recent result for each unique name using javascript. Is there a straightforward way to accomplish this in javascript? This question was inspired by a similar SQL post found here: Get Latest Rates For Each Distinct Rate ...

Issue: Encountered a server error while attempting to serialize an object in JSON format in the Next.js MongoDB environment. The reason for the error is that the specified object ("

Currently, I am in the process of developing an e-commerce platform and integrating a product review system. For this project, I have opted to utilize Next.js along with MongoDB. Everything seems to be functioning smoothly until reviews are submitted, resu ...

React error: The DatePickerProps generic type must have one type argument specified

Date Selection Component: import React from "react" import AdapterDateFns from '@mui/lab/AdapterDateFns'; import { LocalizationProvider } from '@mui/lab'; import { DatePicker, DatePickerProps } from '@mui/lab'; cons ...

Exploring TypeScript and React: Redefining Type Definitions for Libraries

As I transition from JSX to TSX, a challenge has arisen: My use of a third-party library (React-Filepond) This library has multiple prop types The provided types for this library were created by an individual not affiliated with the original library (@ty ...

Need help incorporating metadata in the `not-found.tsx` file within NextJS?

Within my NextJS application, I have a file called not-found.tsx containing basic metadata in the main directory of my app: import { Metadata } from "next"; export const metadata: Metadata = { title: "Page not found", }; export defa ...

Ways to add items to an array adjacent to items sharing a common property value

I have an array consisting of various objects const allRecords = [ { type: 'fruit', name: 'apple' }, { type: 'vegetable', name: 'celery' }, { type: 'meat', name: 'chi ...

Expanding TypeScript Definitions

I've been experimenting with TypeScript and Express. After importing type declarations from Typings, I found the following code: // Imported from typings // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f2 ...

Having trouble testing firebase messaging on my local server

I've encountered an issue while trying to retrieve a token from firebase/messaging for use in notifications. The error message "messaging/unsupported-browser" (FirebaseError: Messaging: This browser doesn't support the API's required to use ...

Parsing JSON objects with identifiers into TypeScript is a common task in web development

I possess a vast JSON object structured like so: { "item1": { "key1": "val1", "key2": "val2", "key3": [ "val4", "val5", ] }, { "item2": { "key1": "val1", "ke ...

Error: The import of 'Link' from 'next/link' in './components/Layout/Navbar.js' was unsuccessful as it is not being exported

/components/Layout/Navbar.js Error: Unable to import 'Link' from 'next/link' (imported as 'Link'). ./components/Layout/Navbar.js Error: Unable to import 'Link' from 'next/link' (imported as 'Link&apos ...

Enhancing RxJS arrays of Observables with supplementary data for preservation

Question: Processing Array of Observables with Metadata in Angular How can I process an array of Observables, such as using forkJoin, while passing additional metadata for each Observable to be used in the pipe and map functions? const source = {animal: & ...

The latest version of NEXT JS is causing an issue with the useTransition hook from react-spring

When using react-spring to create this higher-order component for animating wrapped components, I encountered an error while running NEXT: You might have mismatching versions of React and the renderer (such as React DOM) You might be breaking the Rules of ...

Updating an object property within an array in Angular Typescript does not reflect changes in the view

I am currently delving into Typescript and Angular, and I have encountered an issue where my view does not update when I try to modify a value in an array that is assigned to an object I defined. I have a feeling that it might be related to the context b ...

The initial render of Keen-slider in NextJS can sometimes encounter difficulties when using server-side rendering

While incorporating the keen-slider library v5.4.0 into my nextJS project with TypeScript, I encountered a peculiar issue. The error arises when the keen-slider is initially loaded for the first time, resulting in mismatched transform types causing items ...

Error: The AWS amplify codegen is unable to locate any exported members within the Namespace API

Using AWS resources in my web app, such as a Cognito user pool and an AppSync GraphQL API, requires careful maintenance in a separate project. When modifications are needed, I rely on the amplify command to delete and re-import these resources: $ amplify r ...

Guide to Setting Up Infinite Scroll with Next JS SSG

I recently built a markdown blog using the Next Js documentation and incorporated Typescript. When trying to retrieve a list of blog posts, I utilized getStaticProps as recommended in the documentation. However, my attempts with certain npm packages were u ...

Using 'interface' declarations from TypeScript is unsupported in JS for React Native testing purposes

I have a ReactNative app and I'm attempting to create a test using Jest. The test requires classes from a native component (react-native-nfc-manager), and one of the needed classes is defined as follows export interface TagEvent { ndefMessage: N ...

Exploring the use of generic types in TypeScript interfaces

I have the following two interfaces: export interface TestSchema<S> { data: S; description: string; } export type someType = 'option1' | 'option2'; export interface AnotherInterface { primary: string; secondary: someType; ...

The function you are trying to call is not valid... the specified type does not have any call signatures [ts 2349

Having some trouble using functions from Observable Plot example with a marimekko chart in my TypeScript project. I encountered an error on this particular line: setXz(I.map((i) => sum.get(X[i]))) The code snippet causing the issue is as follows: fu ...

What steps can be taken to resolve the error message "Using 'null' as an index type is not allowed."?

In my TypeScript code, I have a variable called lang declared as a string type value, and a variable called direction declared as an object with two elements. I also have a function that is supposed to return the value of the direction object based on th ...