I ended up here after getting a similar error during next build
, so it might happen to someone else too.
The error was :
TypeError: Cannot read properties of undefined (reading 'env')
I noticed that during build I had the warning : ⚠ You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env
I fixed the error by injecting the correct NODE_ENV
variable :
NODE_ENV=production next build