57

My next.js app works on my machine and was working when deployed on Vercel but now it fails when building on Vercel with the following error:

I've tried deleting node_modules and running npm install a few times but with no joy.

Any help would be hugely appreciated. Thank you!

Running "npm run build" 20:43:24.926
[email protected] build /vercel/5ccaedc9 20:43:24.926
next build 20:43:24.967
internal/modules/cjs/loader.js:983 20:43:24.967
throw err; 20:43:24.967
^ 20:43:24.967
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
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15) 20:43:24.967
at Function.Module._load (internal/modules/cjs/loader.js:862:27) 20:43:24.967
at Module.require (internal/modules/cjs/loader.js:1042:19) 20:43:24.967
at require (internal/modules/cjs/helpers.js:77:18) 20:43:24.967
at Object. (/vercel/5ccaedc9/node_modules/.bin/next:2:46) 20:43:24.967
at Module._compile (internal/modules/cjs/loader.js:1156:30) 20:43:24.967
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10) 20:43:24.967
at Module.load (internal/modules/cjs/loader.js:1000:32) 20:43:24.967
at Function.Module._load (internal/modules/cjs/loader.js:899:14) 20:43:24.967
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) { 20:43:24.967
code: 'MODULE_NOT_FOUND', 20:43:24.967
requireStack: [ '/vercel/5ccaedc9/node_modules/.bin/next' ] 20:43:24.967
} 20:43:24.969
npm ERR! code ELIFECYCLE 20:43:24.969
npm ERR! errno 1 20:43:24.970
npm ERR! [email protected] build: next build 20:43:24.970
npm ERR! Exit status 1 20:43:24.970
npm ERR! 20:43:24.970
npm ERR! Failed at the [email protected] build script. 20:43:24.970
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 20:43:24.974
npm ERR! A complete log of this run can be found in: 20:43:24.974
npm ERR! /vercel/.npm/_logs/2020-06-17T19_43_24_971Z-debug.log 20:43:24.979
Error: Command "npm run build" exited with 1 20:43:25.342
[dmesg] follows: 20:43:25.342
[ 962.449223] ecs-bridge: port 1(veth2a021300) entered disabled state 20:43:25.342
[ 962.453655] device veth2a021300 entered promiscuous mode 20:43:25.342
[ 962.457686] ecs-bridge: port 1(veth2a021300) entered blocking state 20:43:25.342
[ 962.462004] ecs-bridge: port 1(veth2a021300) entered forwarding state 20:43:26.242
Done with "package.json"

Here's my Package.json

{
  "name": "tdwcks",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cjs": "0.0.11",
    "core-util-is": "^1.0.2",
    "framer-motion": "^1.11.0",
    "gray-matter": "^4.0.2",
    "next": "^9.4.4",
    "raw-loader": "^4.0.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-ga": "^3.0.0",
    "react-markdown": "^4.3.1",
    "react-player": "^2.2.0",
    "react-scripts": "^3.4.1"
  },
  "devDependencies": {
    "postcss-preset-env": "^6.7.0",
    "tailwindcss": "^1.4.6"
  }
}
11
  • So you can successfully build on your local machine with npm run build? Commented Jun 15, 2020 at 3:56
  • 1
    Yeah, building on my local machine totally fine. Commented Jun 15, 2020 at 7:51
  • Do you use a .gitignore file ? If yes, what's in it ? Commented Jun 17, 2020 at 14:53
  • @tenclea Nope I don't. Commented Jun 17, 2020 at 16:07
  • Have you tried to use another version of the next module ? Commented Jun 17, 2020 at 16:08

18 Answers 18

100

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
Sign up to request clarification or add additional context in comments.

4 Comments

This is what worked for me. Due to changing letter case of a folder in components folder. The cache didn't track it, meaning it was pushing the old version.
Note that you might be able to do git config core.ignorecase false which will then show files with changed cases for you to re-commit
This worked for me. Also changed the folder from capitalized to lowercase
This is gold! I remember I renamed two folders. Funny thing is, the new name is what I have on my remote repo, but still it didn't work till I ran this command. Thank you so much.
28

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.

5 Comments

This is the only thing that actually works for me.. But why does NextJS expect the node_modules in a production deployment where we already ran the export command.. This is mind-boggling
Where are you deploying your code? I've had success using environment variables in Microsoft Azure: github.com/vercel/next.js/discussions/…
It's deployed to Azure DevOps (private repo) and picked by a custom pipeline. Works fine now, using your updated package.json line for yarn start.
This is the only thing that worked for me too. Is there something messed up locally that it doesn't look in node_modules for package.json commands?
when i do this and try to run my dockerfile, it keeps telling me to give port argument though i give it with "docker run -p 80:3000 my-app"
20

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.

2 Comments

This is the answer, I found tons of question about this problems, and for me in this case it's works, only with the step 1 works for me, thanks!.
Did all that and it said, 'nothing to commit'.
4

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.

1 Comment

Yeah for me i renamed a folder and for some reason the update didn't push to git
3

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.

1 Comment

This is the only thing that actually works for me.. But why does NextJS expect the node_modules in a production deployment where we already ran the export command.. This is mind-boggling
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  
> [email protected] 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! [email protected] 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 [email protected] 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

1 Comment

NB. I have had .next in the .gitignore file all along.
2

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

Comments

2

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

2 Comments

Weird, but solved. thanks
It worked for me also 2025, tf was that?
2

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#

1 Comment

Hero! This is exactly what was causing the issue in my CI/CD pipeline
0

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

5 Comments

Thanks for your help. I've tried both installing typescript and creating a .gitignore file for the .next folder but hasn't solved the issue sadly.
@TomWicks Is there a way for you to completely flush your Vercel app, or to delete this one to create another, and see if it changes anything ?
Updated the error message in the original question. I'll try creating another Vercel app.
still got the same issue :(
@TomWicks this might sound stupid, but do you remember doing anything that could have affected the build operation ? (Adding new modules, etc...)
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)

Comments

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.

Comments

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.

Comments

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.

Comments

0

If node_modules are transferred to server via git as stated in @Joe Haddad's answer. A different strategy for dealing with the issue worked better for me.

On the server, remove all node and next build files carried over to server, re-install and re-build

rm -R node_modules && rm -R .next && rm package-lock.json && npm install && npm run build

Edit or create .gitignore and add node_modules and .next then do the following.

Clear out cached files in git repo, re-add files respecting .gitignore, commit and push changes back to your local computer.

git rm -r --cached ./ && git add ./ && git commit -a -m "Removing ignored files" && git push

On local computer to sync up with newly ignored files. Does not affect local work environment and now you can push and pull successfully.

git pull
npm install

This approach is faster and saves you the trouble of dealing with git stuff on local machine and pushing back to the server.

Comments

0

In my case, I was using turborepo, and I forgot to add the build folder of a library in the outputs options of build

"tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
}

Comments

0

In my case, I opened the project on GitHub and noticed that the folder name didn’t change there, but it did change locally. I renamed the folder directly in the repository, and that solved the problem.

Comments

-1

From Vercel's How do I resolve a 'module not found' error?:

The 'module not found' error is a syntax error that appears when the static import statement cannot find the file at the declared path. This common syntax error is caused by letter-casing inconsistencies that are present in your filename(s) between your repository and local machine, or both.

Why this Happens

One possible cause for this issue is the fact that some filesystems are case-insensitive, however Vercel deployments use a case-sensitive filesystem. Because of this, it is possible that when you change the letter-casing in filenames on your local machine, Git will only pick up changes in your respective static import statements. This would mean that your repository is now syntactically incorrect, resulting in a build error when deploying the repository on the Vercel platform.

How to Resolve

The build logs will indirectly point to the file that is the causing the issue. Make sure that your file's letter-casing correctly matches with its respective static imports. Also make sure that your letter-casing in your filenames and imports are identical between your repository and local machine. If you are using git, make sure git config core.ignorecase false is set in your environment.

1 Comment

Welcome to Stack Overflow. Copy/paste from another source isn't the best way to answer, but it's acceptable when properly attributed, which you did (so thank you for that). However, please make sure that your post is formatted rather than just copying and pasting the text. See How do I format my posts using Markdown or HTML? and the Markdown help for future reference. As a helpful tip - You can click "Edit" under any post here and see how it was formatted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.