ERROR MODULE NOT FOUND whenever I try to run 'npm run dev' using Next.js

Viewed 11077

Whenever I run npm run dev I get this error.

I've tried to delete node_modules and reinstall it using npm install but that didn't work. Then I tried to delete both node_modules and package-lock.json and reinstall them, that didn't work. I even tried upgrading Node to the latest version, but I'm still getting this issue.

I appreciate any help I get. Thank you in advance.

Error: Cannot find module 'C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\postcss\lib\parser'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:952:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:945:15)
    at resolveExports (node:internal/modules/cjs/loader:473:14)
    at Function.Module._findPath (node:internal/modules/cjs/loader:513:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:911:27)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.552 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11590)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735)
    at Object.560 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:400)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735)
    at Object.290 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:260)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735)
    at Object.632 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:3733)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Users\\jaydev\\Desktop\\ecommerce\\fashionsite\\node_modules\\postcss\\package.json'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fashionsite@0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fashionsite@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jaydev\AppData\Roaming\npm-cache\_logs\2020-12-25T07_06_40_981Z-debug.log

package.json: { "name": "fashionsite", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start" }, "dependencies": { "next": "10.0.4", "react": "17.0.1", "react-dom": "17.0.1" } }

7 Answers
  1. stop your dev server (ctrl+c)
  2. delete .next folder in your project's root folder.
  3. delete node_modules folder and package-lock.json file too.
  4. run npm cache clean --force
  5. run npm install
  6. run npm run dev

If the above didn't work then open your file explorer and see if the specified file exists on the specified path or not: C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\postcss\lib\parser.js

if it exists try moving your project's folder to a path other than desktop due to windows permission problems and let me know if the problem is resolved.

I had a similar issue and found that when I was running npm install after removing node_modules it wasn't correctly installing all the dependencies because my node version had switched back to an older version.

Make sure your environment is configured correctly first. For me: nvm use 16.0.0 and then npm install

Also, when you run npm install are there any messages that come up in the command line saying saying a dependency isn't met or something like that, might give you some hints of where to look.

move next.config.js file from you project folder then execute npm run dev.

or

comment the contents of next.config.js.

any of the above methods will help run npm run dev.

make sure u already update/upgrade

sudo apt update
sudo apt upgrade

after u run this command

curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash 
sudo apt-get install -y nodejs

sudo apt install npm

use latest node js repo avoid using sudo apt install nodejs..outdated..

To get rid of this error what you have to do... just update your node.js version Hopefully, it will help you.

In my case it turned out to be a problem with windows permissions. My project was on Desktop and changing its location to a directory with more permissions helped.

Related