In Next.js 16, the return value of require.resolve becomes an integer and the code crashes
Summary I added one tool, which AI agents call from outside, to a service I develop at my own company. When this tool is called, one page selected from a PDF document stored in the service is converted into a JPEG image and included in the response as an image. Before deploying, the AI in charge of development had passed the type check and every unit test. It had also called the tool's function…
In the production build of Next.js 16, the require.resolve function returns an integer instead of a file location, causing a TypeError. This change does not trigger type checking, unit tests, or direct calls, so they cannot detect the issue. The problem occurs when the base for resolving the package location is set to the process's working directory instead of the package directory.
To fix the code, either use the working directory as the base or add a turbopackIgnore annotation. The failure happens right after deployment, and a check starting the same build as production and calling it from outside can help prevent future issues.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.