Files
Luke SandbergandGitHub 3129db08ad [turbopack] Allow withRspack to work even if you already have NEXT_RSPACK set (#84987)
Fix an issue where if a user set `NEXT_RSPACK` as an environment variable then `next` would think it was using rspack but `withRspack` would think it was using `--webpack`.   The issue is that the idempotency check was too strict.

This partially reverts https://github.com/vercel/next.js/pull/84885
2025-10-17 10:18:38 -07:00

21 lines
753 B
JavaScript

Error.stackTraceLimit = 100
module.exports = function withRspack(config) {
if (process.env.NEXT_RSPACK) {
// we have already been called. This can happen when using build workers.
return config
}
if (process.env.TURBOPACK === 'auto') {
delete process.env.TURBOPACK
process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent'
process.env.NEXT_RSPACK = 'true'
} else {
// Either The TURBOPACK flag wasn't set which means --wepack was, or the TURBOPACK flag was set to 1 because --turbopack was passed.
console.trace(
`Cannot call withRspack and pass the ${process.env.TURBOPACK ? '--turbopack' : '--webpack'} flag.`
)
console.error('Please configure only one bundler.')
process.exit(1)
}
return config
}