score:16

Accepted answer

This error typically happens if you're accidentally committing node_modules to your project's Git Repostiory.

Could you try to do the following?

  1. Ensure all changes have been committed and you have a clean directory.
  2. Run rm -rf node_modules (or delete the folder on Windows).
  3. Run git add -A then git commit -m "Remove all module files".
  4. Add node_modules to your .gitignore file (and save).
  5. Run git add -A then git commit -m "Update ignored files".
  6. Verify your directory is completely clean via git status.
  7. Then, run git push. This deployment should work on Vercel.
  8. Finally, re-run npm i or yarn depending on your package manager to get your local copy working.

score:0

What about creating a .gitignore file, and adding the .next folder to it ?

score:0

How I resolved the missing module error on Vercel.

  1. install the package explicitly so that it is present in your package.json
  2. then import the supposed missing module into the app and use it.

For Example (just a scenario) // lets assume lodash is said to be the missing module,

1 Make sure it is present in your package.json

"dependencies": {
    // some dependencies ...
    "lodash": "^4.17.20",
    // some other dependencies ...
},

2 Import and use it in your app (usually, I just console.log the import in a non-production env.)

import LODASH from 'lodash'

if (process.env.NODE_ENV !== 'production') console.log(LODASH)

score:0

I created the folder in lowercased, then, renamed it in capitalized, updated all the imports, but, for some reason, Github didn't update the folder name when I pushed the changes. I needed to renamed with a different name. It worked.

score:0

For me it was a problem with that specific package, when I looked for it in my package.json and under node_modules i couldn't find it. Even though it was working in local builds somehow.

score:0

I added a NODE_ENV="production" environment variable in vercel which hosed everything for me. Once I removed it, things recovered.

score:0

If the program runs normally by executing node_modules/next/dist/bin/next, you should suspect that the symbolic link of the file is broken.
In my case, it occurred during AWS deployment, and it occurred in the process of compressing the files for deployment.
So, I was able to solve the problem by adding the symlinks option during compression as shown below.

zip -r --symlinks xxxx

If it is deployed on a server such as AWS, like me, download the actually distributed program and Check the node_modules/.bin/next file. If the symbolic link is broken, you will need to find and fix the cause of the broken link during the deployment process.

cf) https://github.com/vercel/next.js/discussions/14897#

score:0

  1. Delete package-lock.json (rm package-lock.json)
  2. Delete node_modules (rm -R node_modules)
  3. Switch versions of Node, which is easy if you have Node installed via NVM (nvm install 17, nvm use 17)
  4. Install dependencies again with new version of node (npm install)

I ran into this issue on a server running node 16.15.0 LTS, On my local machine node v16.12.0, and on another server running node v12.22.10 and it was not giving the error.

Took a look at my dependencies and decided to switch to Node 17.

devDependencies": {
    "@types/node": "17.0.23",
    "@types/react": "17.0.43",

After following the steps above and using Node 17 code ran successfully, and no more error.

score:1

in my case it looks like something to do with yarn and the next dependency i.e. inside node_modules/next/dist/bin/next having conflicts information about something.

never quite understand why after using next & building our code into production we still have to rely on the (relatively) heavy module next.

the whole notion of doing build is supposed so that it becomes independent of the build tools.

score:1

I tried all of the above problems and nothing works.

The problem got solved when I changed the version of next.js. In case, someone is searching for a solution and nothing works...

score:2

It seems like I have run into the same error.

The strange thing is that I have been building on Vercel all weekend without any problems, and it only started failing after I added Tailwind CSS to my project.

The first build with the Tailwind CSS addition succeded but styling was not loaded.

You can still see the result at https://rolfmadsen.now.sh/.

The local build with "vercel dev" still runs perfectly.

See the repository at https://github.com/rolfmadsen/search

Error from Build logs:

22:28:35.104  
Running "npm run build"
22:28:35.287  
> search@0.1.0 build /vercel/6ddf29b8
22:28:35.287  
> next build
22:28:35.328  
internal/modules/cjs/loader.js:983
22:28:35.329  
  throw err;
22:28:35.329  
  ^
22:28:35.329  
Error: Cannot find module '../build/output/log'
22:28:35.329  
Require stack:
22:28:35.329  
- /vercel/6ddf29b8/node_modules/.bin/next
22:28:35.329  
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
22:28:35.329  
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
22:28:35.329  
    at Module.require (internal/modules/cjs/loader.js:1042:19)
22:28:35.329  
    at require (internal/modules/cjs/helpers.js:77:18)
22:28:35.329  
    at Object.<anonymous> (/vercel/6ddf29b8/node_modules/.bin/next:2:46)
22:28:35.329  
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
22:28:35.329  
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
22:28:35.329  
    at Module.load (internal/modules/cjs/loader.js:1000:32)
22:28:35.329  
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
22:28:35.329  
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
22:28:35.329  
  code: 'MODULE_NOT_FOUND',
22:28:35.329  
  requireStack: [ '/vercel/6ddf29b8/node_modules/.bin/next' ]
22:28:35.329  
}
22:28:35.331  
npm ERR! code ELIFECYCLE
22:28:35.331  
npm ERR! errno 1
22:28:35.332  
npm ERR! search@0.1.0 build: `next build`
22:28:35.332  
npm ERR! Exit status 1
22:28:35.332  
npm ERR! 
22:28:35.332  
npm ERR! Failed at the search@0.1.0 build script.
22:28:35.332  
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
22:28:35.336  
npm ERR! A complete log of this run can be found in:
22:28:35.336  
npm ERR!     /vercel/.npm/_logs/2020-06-21T20_28_35_332Z-debug.log
22:28:35.342  
Error: Command "npm run build" exited with 1

score:3

I had the same issue. In my github desktop I noticed that a file that was capitalized in the editor was not in the github desktop. Fixed the spelling to match what was showing on github and the project built successfully.

score:8

This answer worked for me: https://stackoverflow.com/a/55541435/3051080

TL;DR; update git cache:

git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master

score:9

I'm having this exact same issue. I think it may be an internal issue with Vercel's deployment infrastructure. Notice the line it is failing on:

Error: Cannot find module '../build/output/log' 20:43:24.967
Require stack: 20:43:24.967
- /vercel/5ccaedc9/node_modules/.bin/next 20:43:24.967

My issue started yesterday, quite unexpectedly -- i.e. with a very simple commit. In my case, previously successful deploys also fail. Likewise, deleting the project and starting over did not help. I am in communication with Vercel support but they have not yet acknowledged the problem is on their end yet or offered any kind of solution.

score:15

I had to edit my package.json to use the next binary that ships in the node_modules/next directory:

"scripts": {
  "start": "node_modules/next/dist/bin/next start -p $PORT"
}

Not the most elegant fix but it works.


Related Query

More Query from same tag