Turbopack Next.js 16: Pino - Cannot find module './transport-stream'
Core Problem
With the latest version of Next.js 16 and Turbopack, users are encountering an error when using Pino for logging. The issue is caused by Turbopack's inability to properly handle the pino/lib/worker.js file, leading to a "Cannot find module './transport-stream'" error.
Solution & Analysis
For Non-Vercel Deployment
To resolve this issue, you can try the following workarounds:
- Switch back to Webpack:
next build --webpack - Add
pino,thread-streamand related pino transport target packages toserverExternalPackages.- Set
serverExternalPackages:next.config.jsconfiguration file. - Install
thread-stream: Runnpm install thread-streamoryarn add thread-stream - Use shim: Add a shim in your
next.config.jsfile to specify the version ofthread-stream
- Set
Example:
module.exports = {
// ...
serverExternalPackages: ['pino', 'thread-stream'],
plugins: [
require('next-shim')({
threadStream: true,
}),
],
};
For Vercel Deployment
Unfortunately, the fixes for Turbopack + non-Vercel deployment do not apply to Turbopack + Vercel deployment. The only workaround is to use Webpack next build --webpack with serverExternalPackages.
Example:
Conclusion
To avoid this issue in Next.js 16 and Turbopack, consider using a different logging library or adjusting your configuration to work around the limitation.