Can't deploy sites. netlify exit non-zero exit code: 2

I can’t deploy sites anymore.
If I update to next12 from 11, site will deploy, but css gets messed up.

11:31:56 AM: Netlify Build                                                 
11:31:56 AM: ────────────────────────────────────────────────────────────────
11:31:56 AM: ​
11:31:56 AM: ❯ Version
11:31:56 AM:   @netlify/build 29.12.1
11:31:56 AM: ​
11:31:56 AM: ❯ Flags
11:31:56 AM:   baseRelDir: true
11:31:56 AM:   buildId: 6491f072d8f6f60cc6c45237
11:31:56 AM:   deployId: 6491f072d8f6f60cc6c45239
11:31:56 AM: ​
11:31:56 AM: ❯ Current directory
11:31:56 AM:   /opt/build/repo
11:31:56 AM: ​
11:31:56 AM: ❯ Config file
11:31:56 AM:   No config file was defined: using default values.
11:31:56 AM: ​
11:31:56 AM: ❯ Context
11:31:56 AM:   production
11:31:56 AM: ​
11:31:56 AM: ❯ Installing plugins
11:31:56 AM:    - @netlify/plugin-nextjs@4.37.4
11:32:06 AM: ​
11:32:06 AM: ❯ Using Next.js Runtime - v4.37.4
11:32:07 AM: ​
11:32:07 AM: @netlify/plugin-nextjs (onPreBuild event)                     
11:32:07 AM: ────────────────────────────────────────────────────────────────
11:32:07 AM: ​
11:32:07 AM: No Next.js cache to restore.
11:32:07 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
11:32:07 AM: ​
11:32:07 AM: (@netlify/plugin-nextjs onPreBuild completed in 14ms)
11:32:07 AM: ​
11:32:07 AM: Build command from Netlify app                                
11:32:07 AM: ────────────────────────────────────────────────────────────────
11:32:07 AM: ​
11:32:07 AM: $ CI= npm run build
11:32:07 AM: > powerstone-nextjs-demo@1.1.0 build
11:32:07 AM: > next build
11:32:08 AM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
11:32:09 AM: info  - Checking validity of types...
11:32:09 AM: warn  - No ESLint configuration detected. Run next lint to begin setup
11:32:09 AM: info  - Creating an optimized production build...
11:32:09 AM: > [PWA] Compile client (static)
11:32:09 AM: > [PWA] Auto register service worker with: /opt/build/repo/node_modules/next-pwa/register.js
11:32:09 AM: > [PWA] Service worker: /opt/build/repo/.next/sw.js
11:32:09 AM: > [PWA]   url: /sw.js
11:32:09 AM: > [PWA]   scope: /
11:32:09 AM: > [PWA] Compile server
11:32:10 AM: node:internal/crypto/hash:71
11:32:10 AM:   this[kHandle] = new _Hash(algorithm, xofLen);
11:32:10 AM:                   ^
11:32:10 AM: Error: error:0308010C:digital envelope routines::unsupported
11:32:10 AM:     at new Hash (node:internal/crypto/hash:71:19)
11:32:10 AM:     at Object.createHash (node:crypto:133:10)
11:32:10 AM:     at BulkUpdateDecorator.hashFactory (/opt/build/repo/node_modules/next/dist/compiled/webpack/bundle5.js:138971:18)
11:32:10 AM:     at BulkUpdateDecorator.update (/opt/build/repo/node_modules/next/dist/compiled/webpack/bundle5.js:138872:50)
11:32:10 AM:     at /opt/build/repo/node_modules/next/dist/compiled/webpack/bundle5.js:59321:9
11:32:10 AM:     at processTicksAndRejections (node:internal/process/task_queues:82:21)
11:32:10 AM:     at runNextTicks (node:internal/process/task_queues:64:3)
11:32:10 AM:     at process.processImmediate (node:internal/timers:447:9) {
11:32:10 AM:   opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
11:32:10 AM:   library: 'digital envelope routines',
11:32:10 AM:   reason: 'unsupported',
11:32:10 AM:   code: 'ERR_OSSL_EVP_UNSUPPORTED'
11:32:10 AM: }
11:32:10 AM: Node.js v18.16.0
11:32:10 AM: ​
11:32:10 AM: "build.command" failed                                        
11:32:10 AM: ────────────────────────────────────────────────────────────────
11:32:10 AM: ​
11:32:10 AM:   Error message
11:32:10 AM:   Command failed with exit code 1: CI= npm run build (https://ntl.fyi/exit-code-1)
11:32:10 AM: ​
11:32:10 AM:   Error location
11:32:10 AM:   In Build command from Netlify app:
11:32:10 AM:   CI= npm run build
11:32:10 AM: ​
11:32:10 AM:   Resolved config
11:32:10 AM:   build:
11:32:10 AM:     command: CI= npm run build
11:32:10 AM:     commandOrigin: ui
11:32:10 AM:     environment:
11:32:10 AM:       - NEXT_PUBLIC_APP_ID
11:32:10 AM:       - NEXT_PUBLIC_ASSOCIATION_ID
11:32:11 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:32:10 AM:       - NEXT_PUBLIC_AWS_ACCESS_KEY
11:32:10 AM:       - NEXT_PUBLIC_AWS_REGION
11:32:10 AM:       - NEXT_PUBLIC_AWS_SECRET_KEY
11:32:10 AM:       - NEXT_PUBLIC_CLIENT_ID
11:32:10 AM:       - NEXT_PUBLIC_COMMUNITY
11:32:10 AM:       - NEXT_PUBLIC_DEVELOPMENT_URL
11:32:10 AM:       - NEXT_PUBLIC_FS_SECRET
11:32:10 AM:       - NEXT_PUBLIC_GOOGLE_ANALYTICS
11:32:10 AM:       - NEXT_PUBLIC_HTTPS_PROD_PORT
11:32:10 AM:       - NEXT_PUBLIC_MINIO_ACCESS_KEY
11:32:10 AM:       - NEXT_PUBLIC_MINIO_ENDPOINT
11:32:10 AM:       - NEXT_PUBLIC_MINIO_SECRET_KEY
11:32:10 AM:       - NEXT_PUBLIC_PRODUCTION_URL
11:32:10 AM:       - NEXT_PUBLIC_SECRET
11:32:10 AM:       - NEXT_PUBLIC_SENDGRID_API_KEY
11:32:10 AM:       - NODE_ENV
11:32:10 AM:       - NEXT_PRIVATE_TARGET
11:32:10 AM:     publish: /opt/build/repo/.next
11:32:10 AM:     publishOrigin: ui
11:32:10 AM:   plugins:
11:32:10 AM:     - inputs: {}
11:32:10 AM:       origin: ui
11:32:10 AM:       package: '@netlify/plugin-nextjs'
11:32:11 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:32:11 AM: Failing build: Failed to build site
11:32:11 AM: Finished processing build request in 55.578s
1 Like

which site is being impacted by this?

I was able to get it solved.
If anyone comes across this issue, check your node version is the same.

thanks for sharing your solution!