#Cannot find module 'next'

1 messages · Page 1 of 1 (latest)

brave aspen
#
  throw err;
  ^

Error: Cannot find module 'C:\Users\xxx\Desktop\xxx\frontend\next'
    at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Function._load (node:internal/modules/cjs/loader:1055:27)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}``` Hello, Has anyone else encountered this error when trying to start the frontend in Next.js? I don't understand why it can't find the modules, I've checked, they are installed, I also consulted with ChatGPT about this, and I've tried downgrading the versions of the dependencies from '19.0.0' for React and React-DOM to 18. Still nothing. This is the content of my package.json ```{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "^15.1.7",
    "react": "^19.0.0",
    "react-dom": "^19.0.0"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "eslint": "^9",
    "eslint-config-next": "15.1.7",
    "postcss": "^8",
    "tailwindcss": "^3.4.1"
  }
}
lone sailBOT
#

Hi @brave aspen. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in your question and the knowledge sources available, it appears you're encountering a "MODULE_NOT_FOUND" error when trying to start your Next.js frontend. This error typically occurs when Node.js is unable to locate the specified module. Let's address this issue step by step:

  1. First, ensure that you have installed all the dependencies correctly. Try deleting your node_modules folder and the package-lock.json file, then run npm install again to reinstall all dependencies.

  2. The error message suggests that Node.js is looking for a module at C:\Users\xxx\Desktop\xxx\frontend\next, which is not the correct path for the Next.js module. This could indicate an issue with how the next command is being invoked.

  3. Your package.json file seems to have some inconsistencies:

    • You're using Next.js version 15.1.7, which doesn't exist. The latest stable version of Next.js is 14.x.x as of my knowledge cutoff.
    • Your React and React-DOM versions (19.0.0) are not compatible with the current stable Next.js versions.
    • Some of your devDependencies versions are incorrect (e.g., eslint: "^9" - the latest major version is 8.x.x).
  4. To resolve these issues, I recommend updating your package.json as follows:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "next": "^14.0.4",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "eslint": "^8.0.0",
    "eslint-config-next": "14.0.4",
    "postcss": "^8",
    "tailwindcss": "^3.4.1"
  }
}
  1. After updating your package.json, delete your node_modules folder and package-lock.json file, then run npm install again.
#
  1. If the issue persists, try running npx next dev instead of npm run dev to start your development server. This ensures that you're using the locally installed Next.js version.

If you continue to encounter issues after trying these steps, it might be helpful to check your project structure and ensure that your next.config.js file (if you have one) is correctly configured.

For more detailed troubleshooting, you may want to refer to the Next.js GitHub issues where similar problems have been discussed and resolved.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@brave aspen Kapa.ai is still learning and improving, please let me know how I did by reacting below.

brave aspen
#

frontend@0.1.0 dev
next dev

  throw err;
  ^

Error: Cannot find module 'C:\Users\xxx\Desktop\next\dist\bin\next'
    at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Function._load (node:internal/modules/cjs/loader:1055:27)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.14.0``` i get the same error with a different path this time
wise pendant
#

npm i -g next