Mar 13, 2020
To fix the out of memory error you should first look to increase the amount of memory allocated to node.js via the environment variable NODE_OPTIONS.
It's happened to me quite a few times when building a Next.js project with a somewhat large number of pages that I get a
NODE_OPTIONSenvironment variable like
NODE_OPTIONS=--max_old_space_size=8192. You can set this anywhere where the
next buildcommand will have access to it when running.
Other weird things that might cause the same error
- You have some kind of circular dependency or reference (eg component self reference)
- If you are using Zeit Now, there is a bug report that this can happen because of a legacy configuration of static assets (not using
- There's an open issue on Next.js for other things that might cause the similar error, but my impression it typically is due to a bad or corrupted Next.js setup since it's not easy to create a reproduction that isn't just due to a very large set of pages etc.