Error encountered: NextJs could not find the specified module, which includes Typescript and SCSS

I am in the process of migrating a Next.js application from .js to .ts and incorporating ScSS. The first error I encounter is during 'npm run dev'. However, when I try 'npm run build', different issues arise that do not seem related to ScSS. It appears to be a broader problem.

Any suggestions would be greatly appreciated?

Migrating from js to ts

touch tsconfig.json
npm run dev
npm install --save-dev typescript @types/react @types/node\n
npm run dev

[ERROR]: NPM RUN DEV Upon running npm run dev, I receive the following errors:

Watchpack Error (initial scan): Error: ENOTDIR: not a directory, scandir '/Users/Edward.Martin/Desktop/Edward/projects/coinGift/node_modules/next/dist/compiled/util/util.js'
error - ./src/pages/_app.js:2:0
Module not found: Can't resolve 'styles/global.scss'
  1 | import React from "react";
> 2 | import "styles/global.scss";
  3 | import "styles/components/index.scss";
  4 | import NavbarCustom from "components/NavbarCustom";
  5 | import Footer from "components/Footer";

[ERROR]: NPM RUN BUILD

Failed to compile.

./src/pages/_app.js
Module not found: Can't resolve 'styles/global.scss' in '/Users/Edward.Martin/Desktop/Edward/projects/coinGift/src/pages'

./src/pages/_app.js
Module not found: Can't resolve 'styles/components/index.scss' in '/Users/Edward.Martin/Desktop/Edward/projects/coinGift/src/pages'

./src/pages/_app.js
Module not found: Can't resolve 'components/NavbarCustom' in '/Users/Edward.Martin/Desktop/Edward/projects/coinGift/src/pages'

./src/pages/_app.js
Module not found: Can't resolve 'components/Footer' in '/Users/Edward.Martin/Desktop/Edward/projects/coinGift/src/pages'

./src/pages/_app.js
Module not found: Can't resolve 'util/analytics' in '/Users/Edward.Martin/Desktop/Edward/projects/coinGift/src/pages'


> Build failed because of webpack errors

Unsuccessful Attempts to Solve

Implementing a scss declaration Despite recommendations to add a module definition into next-env.d.ts, this solution gets overridden (clearly indicated by the comment in the file

// NOTE: This file should not be edited
)

To address this issue, I have created an index.d.ts file in the root directory with the following contents:

declare module "*.module.css";
declare module "*.module.scss";
declare module "*.scss" {
  const content: { [key: string]: any };
  export = content;
}

Additionally, I included "index.d.ts" in the include section of tsconfig.json

Installing Other Dependencies

npm i style-loader, css-loader, typescript

Answer №1

Oh, that's interesting, I recently compared the contents of the eslintrc.json and the prettierrc.json

After some investigation, it appears that I had to include:

    "semi": true,

Answer №2

Unfortunately, this solution did not resolve the issue for me. However, after including the following code in my tsconfig.json:

"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],

I was able to successfully fix the problem.

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

Angular messaging service error TS2769: There is no overload that fits this call

Currently, I am attempting to utilize a messenger service to send products to the cart component. Within the 'Product' class, there are various product attributes stored. Although I managed to successfully log the product to the console in the ca ...

Angular 2 file upload encountering CORS issue leading to 401 unauthorized error

Encountered a "401 Unauthorized" error in Chrome and Firefox while attempting to upload files using angular 2 CLI to an apache2-server with a PHP backend. Despite trying three different node modules, the issue persists from the OPTIONS-preflight stage, ...

When evaluating objects or arrays of objects to determine modifications

How can we detect changes in table data when users add input to cells? For example, if a user clicks on a cell and adds an input, the function should return TRUE to indicate that there are changes. If the user just clicks on the cell without making any ch ...

The loading indicator fails to appear when navigating to a different page

I recently started using Next.js and have set up 3 pages: index.js categories/index.js categories/[slug].js To enhance the user experience, I decided to incorporate the library called NProgress, which displays a loading line at the top of the viewport wh ...

The key is not applicable for indexing the type as expected

Here is the TS code I am working with: type Fruit = { kind: "apple" } | { kind: "grape"; color: "green" | "black" }; type FruitTaste<TFruit extends Fruit> = TFruit["kind"] extends "apple" ? "good" : TFruit["color"] extends "green" ? "good" : ...

Demonstrate JSON data using ngFor loop in Angular

Need some assistance here. Trying to display data from a .json file using a ngFor loop. However, I keep running into the following error in my code: Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgF ...

Debugging Issue with Webpack 2

Having trouble upgrading from web pack 1 to web pack 2. I encountered an error when trying to run the code... The error message reads: WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object t ...

Issue: The useHref() function is restricted to usage within a <Router> component. This error occurred within the register.js file

Hey there, I'm currently working on a reactjs app and everything is running smoothly with the routes except for the register user function which is throwing an error: Error: useHref() may be used only in the context of a component. I am utilizing fire ...

Stripe: What are the methods available to collect data for storage in my platform?

I'm in the process of integrating Stripe into my platform, which is built using Next.js and Laravel. I'm struggling to understand how I can retrieve the data from a transaction and store it in MY Platform's database. For instance, when a us ...

Navigating pages using a dropdown menu in NEXT.js

Looking to navigate to different pages based on dropdown selection, but unsure how to do so in React and Next. "use client" import Link from 'next/link'; function Home() { return ( <main> <h1>Hello</h1> ...

Encountering a problem when launching the "vite-express" template on the Remix app (TSConfckParseError: error resolving "extends")

I recently launched a brand-new [email protected] project using the remix-run/remix/templates/vite-express template after executing this command: npx create-remix@latest --template remix-run/remix/templates/vite-express However, upon trying to run th ...

Having trouble accessing undefined properties? Facing issues with the latest Angular version?

Why am I encountering an error and what steps can be taken to resolve it? Currently using the latest version of Angular. ERROR TypeError: Cannot read properties of undefined (reading 'id') Here is the JSON data: { "settings": [ { ...

Angular 17 | Angular Material 17.3.1: Problem encountered with Angular Material form field focus and blur event handling

I attempted to apply (blur) and (focus) effects to my mat-form-field input field, but it seems like they are not working properly on my system. Here is a code snippet that resembles what I am using: html file <form class="example-form"> ...

Implementing unique metadata tags for Next.js version 13

Can custom metatags be created with Next 13 and the ability to control if it should be labeled as "name" or "property"? I attempted to add Facebook metatags such as 'og:updated_time', but that specific key is not available. Using 'other&apo ...

Does Angular 8 development mode implement tree-shaking?

I am curious to know if tree-shaking occurs during Angular 8 development mode. When running the following command: ng build I understand that tree-shaking happens when I use the command below: ng build --optimization=true|false ...

Error alert: TypeScript typings issue - Naming conflict with Promise / Failure to locate name Promise

I am currently working on a client/server JavaScript application and I am facing a significant issue with Promises. It appears that they are either undefined or duplicated, and this problem seems to be related to the @types package. npm install --save @ty ...

Interacting with User Input in React and TypeScript: Utilizing onKeyDown and onChange

Trying to assign both an onChange and onKeyDown event handler to an Input component with TypeScript has become overwhelming. This is the current structure of the Input component: import React, { ChangeEvent, KeyboardEvent } from 'react' import ...

Using React with an Array of Promises in Typescript

I have a function that looks like this: function queryProposals(hash:string) { let result = api?.query.backgroundCouncil.proposalOf( hash,(data1:any)=>{ let injectedData = data1.toPrimitive().args.account as InjectedAccou ...

Importing TypeScript Modules from a Custom Path without Using Relative Paths

If we consider the following directory structure: - functions - functionOne - tsconfig.json - index.ts - package.json - node_modules - layers - layerOne - tsonfig.json - index.ts - index.js (compiled index.ts ...

Something went wrong trying to retrieve the compiled source code of https://deno.land/[email protected]/path/mod.ts. It seems the system is unable to locate the specified path. (os error 3)

Upon executing my main.ts script using deno, I encounter the following error message: error: Failed to retrieve compiled source code from https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcccbdbff8f918a86918f"& ...