Next.js project not deploying: build errors

PLEASE help us help you by writing a good post!

  • We need to know your netlify site name. Example: gifted-antelope-58b104.netlify.app
  • DNS issues? Tell us the custom domain, tell us the error message! We can’t help if we don’t know your domain.
  • Build problems? Link or paste the FULL build log & build settings screenshot
  • Did you try Ask Netlify, our generative AI chatbot, before posting? It pulls info from Support Guides and recent solved forums posts.

The better the post - the faster the answer.

Site name: statuesque-froyo-9b8827
https://statuesque-froyo-9b8827.netlify.app/

I tried to copy and paste the build log but I get an error stating that new users can only post 6 links.

Hi @lellis09,
You can copy a snippet of where the error is happening in your build logs here so that I can help with the debugging.

Thanks.

Hello new to using both Next.js and Netlify. I just started the build process an it failed.
Site name : soft-cucurucho-6512c4
Below is a image of my configuration settings

8:37:17 AM: Netlify Build                                                 
8:37:17 AM: ────────────────────────────────────────────────────────────────
8:37:17 AM: ​
8:37:17 AM: ❯ Version
8:37:17 AM:   @netlify/build 29.32.0
8:37:17 AM: ​
8:37:17 AM: ❯ Flags
8:37:17 AM:   baseRelDir: true
8:37:17 AM:   buildId: 65a14e94c9a4b000a2702ccf
8:37:17 AM:   deployId: 65a14e94c9a4b000a2702cd1
8:37:17 AM: ​
8:37:17 AM: ❯ Current directory
8:37:17 AM:   /opt/build/repo
8:37:17 AM: ​
8:37:17 AM: ❯ Config file
8:37:17 AM:   No config file was defined: using default values.
8:37:17 AM: ​
8:37:17 AM: ❯ Context
8:37:17 AM:   production
8:37:17 AM: ​
8:37:17 AM: ❯ Installing plugins
8:37:17 AM:    - @netlify/plugin-nextjs@4.41.3
8:37:28 AM: Failed during stage "building site": Build script returned non-zero exit code: 2
8:37:26 AM: ​
8:37:26 AM: ❯ Using Next.js Runtime - v4.41.3
8:37:27 AM: ​
8:37:27 AM: @netlify/plugin-nextjs (onPreBuild event)                     
8:37:27 AM: ────────────────────────────────────────────────────────────────
8:37:27 AM: ​
8:37:27 AM: No Next.js cache to restore.
8:37:27 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
8:37:27 AM: ​
8:37:27 AM: (@netlify/plugin-nextjs onPreBuild completed in 51ms)
8:37:27 AM: ​
8:37:27 AM: Build command from Netlify app                                
8:37:27 AM: ────────────────────────────────────────────────────────────────
8:37:27 AM: ​
8:37:27 AM: $ next build
8:37:27 AM: bash: next: command not found
8:37:27 AM: ​
8:37:27 AM: "build.command" failed                                        
8:37:27 AM: ────────────────────────────────────────────────────────────────
8:37:27 AM: ​
8:37:27 AM:   Error message
8:37:27 AM:   Command failed with exit code 127: next build (https://ntl.fyi/exit-code-127)
8:37:27 AM: ​
8:37:27 AM:   Error location
8:37:27 AM:   In Build command from Netlify app:
8:37:27 AM:   next build
8:37:27 AM: ​
8:37:27 AM:   Resolved config
8:37:27 AM:   build:
8:37:27 AM:     command: next build
8:37:27 AM:     commandOrigin: ui
8:37:27 AM:     environment:
8:37:27 AM:       - NEXT_PRIVATE_TARGET
8:37:27 AM:     publish: /opt/build/repo/.next.
8:37:27 AM:     publishOrigin: ui
8:37:27 AM:   plugins:
8:37:27 AM:     - inputs: {}
8:37:27 AM:       origin: ui
8:37:27 AM:       package: "@netlify/plugin-nextjs"
8:37:28 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
8:37:28 AM: Failing build: Failed to build site
8:37:28 AM: Finished processing build request in 18.965s

please disregard this I actually just realised my github repo is empty but I will get in touch if I need help later. Thank you!

1 Like

okay i am having issues using fs getting the following error mulitple times
Module not found: Can"t resolve “fs”
I saw this thread node.js - Module not found: Can't resolve 'fs' in Next.js application - Stack Overflow
seems like the same issue however I am not really sure where I need to add that next.config.js file

Hi @Kysetopher, the instructions in the Stack Overflow link states you should add a next.config.js in your project root if there is none.
After the content of the next.config.js should look like the code below.

module.exports = {
  webpack5: true,
  webpack: (config) => {
    config.resolve.fallback = { fs: false };

    return config;
  },
};

Note that the above configuration is for Webpack 5

Thanks.

Hello clarence
thanks for your help. I found a solution to that problem but it seems I am still having general build issues. Im not sure whats causing the issue now but my research is telling me I may not have everything correct in my package.json file. Can i touch base with you later for help. I will be available around 6:30 PCT

Hi @Kysetopher I want to find out if you have been able to resolve your problem.
Thanks.