Nextjs compilation error - Unable to locate module: Cannot resolve 'module'

Currently, I am immersed in a nextjs project using wagmi hooks. Recently, Nextjs presented me with an error message indicating that it cannot resolve the 'module' (refer to the error message below). This occurred after resolving the initial errors related to the missing 'fs module' and 'child_process module' by incorporating a fallback statement in my next.config.js file.

Within my project, I employ wagmi hooks for interactions with deployed smart contracts. I have a suspicion that this might have triggered the chain of error messages. Any assistance or guidance on this matter would be greatly appreciated. Thank you!

Error message:

./node_modules/eslint-config-next/index.js:42:0 Module not found: Can't resolve 'module'

Reference code in /eslint-config-next/index.js:42:0

const mod = require('module')
const resolveFilename = mod._resolveFilename
mod._resolveFilename = function (request, parent, isMain, options) {
  const hookResolved = hookPropertyMap.get(request)
  if (hookResolved) {
    request = hookResolved
  }
  return resolveFilename.call(mod, request, parent, isMain, options)
}

Here is a snippet from my next.config.js:

const nextConfig = {
  reactStrictMode: true,
  // The following was added to suppress the initial 'fs module not found' and 'child_process module not found' errors
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fallback.fs = false;
      config.resolve.fallback.tls = false;
      config.resolve.fallback.net = false;
      config.resolve.fallback.child_process = false;
    }

    return config;
  },
  future: {
    webpack5: true,
  },
  fallback: {
    fs: false,
    tls: false,
    net: false,
    child_process: false,
  },
};

module.exports = nextConfig;

This is an excerpt from my package.json:

{
  "name": "slot_next",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@next/font": "13.1.2",
    "@nodelib/fs.scandir": "^2.1.5",
    "@rainbow-me/rainbowkit": "^0.8.1",
    "eslint": "8.31.0",
    "eslint-config-next": "13.1.2",
    "ethers": "^5.7.2",
    "next": "13.1.2",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "wagmi": "^0.9.6"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.21",
    "tailwindcss": "^3.2.4"
  }
}

In an attempt to troubleshoot, I executed both npm cache clear --force and npm install, but unfortunately, that did not alleviate the issue.

Answer №1

Here's a straightforward fix!

All you need to do is remove the node_modules and package-lock.json files, then follow these steps:

npm cache clear --force

Next,

npm install

I believe this will resolve your issue.

Answer №2

Try simply deleting the contents of tsconfig.json

After that, execute the command "yarn run dev" or "npm run dev" in your terminal.

This solution worked like a charm for me.

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

Is there a directive in AngularJS that allows for binding HTML templates using ng-bind-html

I'm working on a directive that has the ability to use dynamic templates with expressions inside them. The challenge I face is if I use ng-bind-html, the expression won't be evaluated properly. On the other hand, using ng-bin-template results in ...

Firebase is displaying an error when using onSnapshot, specifically when a value is being waited on from an

Currently, I am working on an application where I am categorizing posts and users based on a specific room ID. I am adding a roomid property to both the user and every post. However, when attempting to fetch all posts belonging to a particular room ID, I e ...

Having trouble creating a report with an HTML screenshot using Protractor

Need assistance with generating reports using a html screenshot in Protractor. I have followed all the necessary steps but encountered an error. Any help would be appreciated. Here is my conf.js: // Sample configuration file. var HtmlReporter = require(& ...

Is it possible to directly utilize functions from an imported JavaScript library, such as Change Case, within the template of a Vue component?

After successfully importing and using the Change Case library within the <script></script> element of a Vue component, I now seek to directly utilize the Change Case functions in the template itself. As of now, my understanding is that when d ...

Is it possible to display the content below the row of the clicked element when it is selected?

I am currently working on building a team page similar to the layout at My goal is to create a row of elements that float or display inline, with hidden content revealed beneath each selected element, pushing subsequent rows further down. Unfortunately, m ...

What is the best way to strip out a changing segment of text from a string?

let: string str = "a=<random text> a=pattern:<random text (may be fixed length)> a=<random text>"; In the given string above, let's assume that a= and pattern are constants. It is possible that there may or may not be a ...

Turning HTML into an image with the power of JavaScript

Utilizing html2canvas to convert a div into an image, everything is functioning properly except for the Google font effect. The image shows how it eliminates the effect from the text. https://i.stack.imgur.com/k0Ln9.png Here is the code that I am using f ...

Encountering an error when trying to use this.setState

I'm currently working on developing a simple react application that consists of a component. In this component, I am attempting to adjust the state when a link is clicked. However, I'm encountering an issue where the setState function is not bein ...

Comparing XDomainRequest and XMLHTTPRequest - which one to choose

Our team is currently developing an application utilizing PixiJS that integrates a dynamic json loader. The .json files are loaded using the following logic: if(window.XDomainRequest) { this.ajaxRequest = new window.XDomainRequest(); } else if (windo ...

Error message: A circular structure is being converted to JSON in Node.js, resulting in

So here is the error message in full TypeError: Converting circular structure to JSON --> starting at object with constructor 'Socket' | property 'parser' -> object with constructor 'HTTPParser' --- prope ...

I possess a function that can retrieve the key of an Object, but now I am faced with the task of accessing the actual Object using this value in JavaScript

This is my first time seeking advice on a technical issue. I'm currently working with the following function: export function sendRequest<T>(req: RawRequest, options) { const start = Date.now(); const reqOptions: CoreOptions = { ...

Incorporate JavaScript functionality with HTML dropdown lists

I am attempting to achieve the following: The user can choose between "Option One" or "Option Two". If they select "Option One", the result will be 66 + 45, and if they select "Option Two", the result will be 35 + 45. How can I make this work using a com ...

Interested in creating a weather application that changes color based on the time of day

My attempt to create a weather app with a glowing effect has hit a roadblock. I want the app to glow "yellow" between 6 and 16 hours, and "purple" outside of those hours. I have assigned classes for AM and PM elements in HTML, and styled them accordingly i ...

Ensure the navigation bar is horizontally centered by utilizing Next.js and Tailwind CSS

Hello, I'm looking to horizontally align my navbar. Can someone help me with this? <nav className='flex items-stretch flex-wrap bg-blue-300 p-3 '> <div className='flex px-4 align-middle'> <Link href ...

Utilizing requirejs for handling asynchronous callback functions with ajax

If I need to take advantage of the jQuery AJAX API features and customize settings for each ajax call made by my application, it can be done like this: For example, imagine a page that showcases employee information in a table using ajax calls to an API. ...

Customizing the language parameter for the apply button script on LinkedIn

Our company's website features the AWLI button which allows users to apply for jobs using their LinkedIn profile. <div name="widget-holder"> <script type="text/javascript" src="https://www.linkedin.com/mj ...

Accurate representation of a JavaScript object using Node.js Express

I have a certain structure that I need to display on my JADE page, so I created a JSON-like object to store the data. This is how the JSON object looks like : var dataSet1 = { meta: { "name": "Some text", "minimum": mini_2, "ma ...

Using jQuery and AJAX to submit a dynamic form

I am currently facing an issue with cloning a HTML drop down list using jQuery. The main problem I am encountering is that there seems to be no restriction on the number of cloned sections, and I need to store all these sections in a mySQL database. How c ...

Loop through a JSON object using a sequence of setTimeout() functions

After running another function, I have retrieved a JSON object stored in the variable 'json_result'. My objective is to log each individual JSON part (e.g. json_result[i]) after waiting for 5 seconds. Here was my initial attempt: for (let key ...

Guide for integrating the shadcn/ui Range Date Picker within a Form

Encountering an issue with using The Range Date Picker within the Form component. Specifically, I am looking to store {from, to} values of the range in an object, however, utilizing an object as a Form field value results in error messages not functioning ...