Skip to content

Error: Your next.config.js must set the "target" property to one of: serverless, experimental-serverless-trace for conditional target #97

Closed
@amuttsch

Description

@amuttsch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions