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

Looking to incorporate ipcRenderer from Electron into your Angular project? Having trouble accessing variables passed from the preload script?

I am struggling with incorporating ipcRenderer into the 'frontend' code of my electron app. Although I found examples in the documentation that use require, this method is not accessible on the frontend side where I am utilizing Angular. In the ...

The Next.js payload CMS does not retrieve environment variables from the .env file

PAYLOAD_SECRET is not provided for the payload cms: import path from "path"; import type { InitOptions } from "payload/config"; import payload from "payload"; dotenv.config({ path: path.resolve(__dirname, "./.env") ...

Overlooking errors in RxJs observables when using Node JS SSE and sharing a subscription

There is a service endpoint for SSE that shares a subscription if the consumer with the same key is already subscribed. If there is an active subscription, the data is polled from another client. The issue arises when the outer subscription fails to catch ...

What is the best way to implement multiple templates for a single component?

Is there a way to configure my Home Component based on the user's role? For instance: If the employee is an admin, then the home component should load the template URL designed for admins. Likewise, if the employee is a cashier, then the home compo ...

Tips for inserting a string into an array nested within an object stored in a state array

Currently, the variable sizeVariant is a string array and I am trying to append strings to it using an onClick event. The function findIndex seems to be working fine. However, there seems to be an issue with the concatenation section. It appears that using ...

Using next.js with SSG can lead to numerous fetch requests resulting in 404 errors for JSON files

Currently, I am utilizing SSG with Next.js and executing "next export" to generate static files in the /out folder. However, upon deployment of the application, I notice an influx of HTTP GET requests from router.js. https://i.stack.imgur.com/Gr6dU.png Th ...

Sorting arrays in Typescript

Is there a way to alphabetically sort an array of objects in Typescript based on a specific field? The array I have currently looks like this - https://i.stack.imgur.com/fQ3PA.png I'm interested in sorting it alphabetically by the 'channel' ...

The attempt to access the property "collectionName" of an undefined object resulted in an error with the Mongoose models

Having some trouble fetching data from the Note collection in a local MongoDB database using Mongoose with Next.js. I keep encountering an error that says "Cannot read properties of undefined (reading 'note')". Any insights on what might be causi ...

The use of fs.writeFileSync is invalid and will not work for this operation

Encountering an issue while working with fs in next.js, receiving the following error message: TypeError: fs.writeFileSync is not a function Here's a snippet from my package.json: resolve: { fallback: { "fs": false }, } ...

What steps can I take to resolve the spawn unknown error when using npx create-next-app in Visual Studio Code (VSCode)?

Every time I attempt to create a new app using either vscode or cmd, I encounter a spawn unknown error. The error message says "Aborting installation. Unexpected error. Please report it as a bug: Error: spawn UNKNOWN". Unfortunately, the installation abo ...

Safari 15.6.1 does not support background video playback in Next.js

Currently using Safari version 15.6.1 for a small website project, I have encountered an issue where the video appears frozen with an arrow in the middle. Oddly enough, this problem only occurs on Safari as both Chrome and Firefox display the code correctl ...

Sharing information between different components in React can be done using props, context, or a

When attempting to edit by clicking, the parent information is taken instead of creating a new VI. I was able to achieve this with angular dialog but I am unsure how to do it with components. This is done using dialog: <div class="dropdown-menu-item" ...

Scoped Styles rarely stand a chance against more dominant styles

I'm facing a scope issue while learning Vue. Question: I am trying to make sure that the styles in profile.vue do not override the ones in sidebar.vue. I want the sidebar to have a red background and the profile section to be blue. Shouldn't usi ...

choosing between different options within Angular reactive forms

I am attempting to create a select element with one option for each item in my classes array. Here is the TypeScript file: @Component({ selector: 'app-create-deck', templateUrl: './create-deck.component.html', styleUrls: [' ...

What is the process of importing an IIFE-based JavaScript module into an Angular TypeScript application?

I have come across a third-party SDK that is structured as an oldschool IIFE based module. The code looks something like this: var ThirdPartySDK = (function() { var export = {}; // Adding some methods to export return export; })(); To use this SD ...

Contrasting the utilization of `typeof` with a constant and `enum` in TypeScript

Can you explain the distinction between using typeof with a constant and an enum in TypeScript? For example: const TYPE_A = 'a' const TYPE_B = 'b' type MyType = | typeof TYPE_A | typeof TYPE_B type Result = { name: string type ...

Issue with Vue.js webpack encountering problems when importing a CSS file from an external library

I'm in the process of integrating the aos animation library into my testing app. I installed it using yarn add aos, and in my Vue application, I've included the following code: <script> .... import AOS from 'aos/dist/aos.js' imp ...

After placing two divs within another div and applying justify content, an unexpected blank space has appeared

I am currently working on a website project using the Next.js framework for React and Tailwind CSS for styling. However, I have come across an issue that is causing some trouble. My goal is to position an image on the right side of the page while keeping t ...

When executing npm release alongside webpack, an error is triggered

Currently, I am following a tutorial provided by Microsoft. You can access it through this link: https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr-typescript-webpack?view=aspnetcore-3.1&tabs=visual-studio However, when attempting to run ...

What is the best way to decide on a method's visibility depending on who is calling

I am curious about the best approach for providing methods with "privileged access" that can only be called by specific object types. For instance, if you have a Bank object with a collection of Accounts, you may want to allow the Bank object to call acco ...