Closed
Description
I'm using a conditional to determine if our next application will be compiled in server
or serverless
mode. The plugin, however, does not support this kind of config:
const isServerless = !!process.env['NEXT_SERVERLESS'];
module.exports = withOptimizedImages(
withBundleAnalyzer(
withSourceMaps({
target: isEnvProduction && isServerless ? 'serverless' : 'server',
poweredByHeader: false,
...
})
)
);
My netlify.toml
looks like this:
[build]
command = "yarn run build:serverless"
functions = "out_functions"
publish = "out_publish"
[[plugins]]
package = "@netlify/plugin-nextjs"
The build:serverless
task sets the environment variable NEXT_SERVERLESS
:
"build:serverless": "yarn run clean && NODE_ENV=production NEXT_SERVERLESS=true SOURCE_MAPS_ENABLED=false next build",
A workaround is to sed
the config in our CI pipeline before running netlify build
:
sed -i "s/target: isEnvProduction && isServerless ? 'serverless' : 'server',/target: 'serverless',/g" next.config.js