8

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" } }

Jahmar Lawrence
  • 103
  • 1
  • 1
  • 8

12 Answers12

19
  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.

Abbas Hosseini
  • 1,545
  • 8
  • 21
  • Yeah I followed your first steps and it didn't work. So I tried moving my project folder to documents and then I checked to see that parser.js file exist and it does. I was able to see the file on my browser and in my text editor. But when I remove the .js and tried to access the module node is looking for but it doesn't exist so idk. Error: Cannot find module 'C:\Users\jaydev\Documents\ecommerce\fashionsite\node_modules\postcss\lib\parser' . Like its looking for parser, but parser doesnt exist on my machine. Only the parser.js file exist. – Jahmar Lawrence Dec 25 '20 at 19:18
  • there is nothing wrong with .js extension so please don't rename the file and let it be parser.js as it was. can you post your package.json file contents ? – Abbas Hosseini Dec 25 '20 at 19:56
  • { "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" } } – Jahmar Lawrence Dec 25 '20 at 20:05
  • have you tried cleaning npm cache? I edited my answer and added a step (4) – Abbas Hosseini Dec 25 '20 at 20:06
  • Yep unfortunately that didn't work, I'm getting the same error – Jahmar Lawrence Dec 25 '20 at 20:33
  • It seems that something is wrong with your Node js. npm or windows system. I even tried deleting the specified file on my own system but the error wasn't the same and it was Cannot find module './parser', try npm uninstall -g css poscss. and see if you've installed latest LTS version of node. wish you good luck – Abbas Hosseini Dec 25 '20 at 21:11
1

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

dev__rezo
  • 61
  • 1
  • 5
1

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.

minasrc
  • 89
  • 8
  • I applied your Suggestion and it worked for me. Thanks. The problem was that I had my project on Desktop. Although I am still not sure what these permission problems exactly are, So can you explain it a bit! – Sunny Oct 28 '22 at 16:01
1

For me deleting next.config.js and running npm run dev worked.

pdutra145
  • 11
  • 2
0

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.

Hughes
  • 366
  • 4
  • 13
0

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.

JoKer
  • 5
  • 4
0

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..

0

I also got this error:

$ npm run start

> kalyna@0.1.0 start
> next start

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - [next-export-optimize-images]: Configuration was not loaded. (This is optional.)
Error: Cannot find module '/home/matachi/proj/kalyna/.next/server/pages/index.js'
Require stack:
- /home/matachi/proj/kalyna/node_modules/next/dist/server/require.js
- /home/matachi/proj/kalyna/node_modules/next/dist/server/next-server.js
- /home/matachi/proj/kalyna/node_modules/next/dist/server/next.js
- /home/matachi/proj/kalyna/node_modules/next/dist/server/lib/start-server.js
- /home/matachi/proj/kalyna/node_modules/next/dist/cli/next-start.js
- /home/matachi/proj/kalyna/node_modules/next/dist/lib/commands.js
- /home/matachi/proj/kalyna/node_modules/next/dist/bin/next
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.mod._resolveFilename (/home/matachi/proj/kalyna/node_modules/next/dist/build/webpack/require-hook.js:27:32)
    at Function.mod._resolveFilename (/home/matachi/proj/kalyna/node_modules/next/dist/build/webpack/require-hook.js:27:32)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.requirePage (/home/matachi/proj/kalyna/node_modules/next/dist/server/require.js:58:12)
    at /home/matachi/proj/kalyna/node_modules/next/dist/server/load-components.js:61:73
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.loadComponents (/home/matachi/proj/kalyna/node_modules/next/dist/server/load-components.js:61:26) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/matachi/proj/kalyna/node_modules/next/dist/server/require.js',
    '/home/matachi/proj/kalyna/node_modules/next/dist/server/next-server.js',
    '/home/matachi/proj/kalyna/node_modules/next/dist/server/next.js',
    '/home/matachi/proj/kalyna/node_modules/next/dist/server/lib/start-server.js',
    '/home/matachi/proj/kalyna/node_modules/next/dist/cli/next-start.js',
    '/home/matachi/proj/kalyna/node_modules/next/dist/lib/commands.js',
    '/home/matachi/proj/kalyna/node_modules/next/dist/bin/next'
  ]
}

I fixed it by deleting the .next directory and restarting the dev server:

$ rm -rf .next 
$ npm run dev

> kalyna@0.1.0 dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - [next-export-optimize-images]: Configuration was not loaded. (This is optional.)
event - compiled client and server successfully in 9.9s (173 modules)
wait  - compiling / (client and server)...
event - compiled client and server successfully in 1809 ms (300 modules)
Daniel Jonsson
  • 3,261
  • 5
  • 45
  • 66
0

My solution to that is updating my node version. I got the same error in 10.18. version and I upgraded to the latest and it works fine already, maybe it will works for you too.

Hope it helps this issue. it also works in 17.3.0 but right this moment the latest is 18.12.0.

0

I had the same problem and I found figured out the solution by following the linked explanation: https://nextjs.org/docs/messages/module-not-found.

The swr module has to be installed using a package manager.

When using npm: npm install swr
When using yarn: yarn add swr

where swr is the missing module. In my case as my missing module was graphql:

 yarn add graphql

did the trick

Virgilio Lino
  • 91
  • 1
  • 5
0

I had similar problem, when I typed (npm run dev), it showed me:

nameofproject@1.1.0 dev next dev.

I used node version 14.something. I updated my node version to latest, today latest version is 18.15.0 LTS

then I typed (npm run dev) and it is working for me.

pete
  • 45
  • 5
-1

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 ->

https://hidayatabisena.medium.com/how-to-solve-npm-err-code-elifcycle-when-running-npm-run-dev-on-your-next-js-project-4794226d040f

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Emmanuel Meric de Bellefon Feb 27 '22 at 11:45