'ERROR MODULE NOT FOUND whenever I try to run 'npm run dev' using Next.js
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! [email protected] dev: `next dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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" } }
Solution 1:[1]
- stop your dev server (ctrl+c)
- delete
.nextfolder in your project's root folder. - delete
node_modulesfolder andpackage-lock.jsonfile too. - run
npm cache clean --force - run
npm install - 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.
Solution 2:[2]
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.
Solution 3:[3]
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.
Solution 4:[4]
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..
Solution 5:[5]
Make sure you are in the right directory when using npm run dev. You can also try switching to yarn.
I found this article helpful ->
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Hughes |
| Solution 3 | |
| Solution 4 | |
| Solution 5 | leul--Dev |
