Skip to content

fix: disable serverless targets #739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ publish = ".next"
package = "@netlify/plugin-nextjs"
```

If you previously set `target: "serverless"` or a custom `distDir` in your `next.config.js`, or set `node_bundler` or `external_node_modules` in your `netlify.toml` these are no longer needed and can be removed.
If you previously set `target: "serverless"` or a custom `distDir` in your `next.config.js`, or set `node_bundler` or `external_node_modules` in your `netlify.toml` these are no longer needed and can be removed.

The `serverless` and `experimental-serverless-trace` targets are deprecated in Next 12, and all builds with this plugin will now use the default `server` target.

If you are using a monorepo you will need to change `publish` to point to the full path to the built `.next` directory, which may be in a subdirectory. If you have changed your `distDir` then it will need to match that.

Expand Down
8 changes: 0 additions & 8 deletions src/helpers/verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ const outdent = require('outdent')
const prettyBytes = require('pretty-bytes')
const { satisfies } = require('semver')

exports.verifyBuildTarget = (target) => {
if (target !== 'server') {
console.log(
yellowBright`Setting target to ${target} is no longer required. You should check if target=server works for you.`,
)
}
}

// This is when nft support was added
const REQUIRED_BUILD_VERSION = '>=18.16.0'

Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const { generateFunctions, setupImageFunction, generatePagesResolver } = require
const {
verifyNetlifyBuildVersion,
checkNextSiteHasBuilt,
verifyBuildTarget,
checkForRootPublish,
logBetaMessage,
checkZipSize,
Expand All @@ -33,6 +32,10 @@ module.exports = {
verifyNetlifyBuildVersion({ failBuild, ...constants })

await restoreCache({ cache, publish })

netlifyConfig.build.environment ||= {}
// eslint-disable-next-line unicorn/consistent-destructuring
netlifyConfig.build.environment.NEXT_PRIVATE_TARGET = 'server'
},

async onBuild({
Expand All @@ -48,8 +51,6 @@ module.exports = {

const { appDir, basePath, i18n, images, target, ignore } = await getNextConfig({ publish, failBuild })

verifyBuildTarget(target)

configureHandlerFunctions({ netlifyConfig, ignore, publish: relative(process.cwd(), publish) })

await generateFunctions(constants, appDir)
Expand Down
10 changes: 9 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ beforeEach(async () => {
cleanup = tmpDir.cleanup

netlifyConfig.build.publish = path.posix.resolve('.next')
netlifyConfig.build.environment = {}

netlifyConfig.redirects = []
netlifyConfig.functions[HANDLER_FUNCTION_NAME] && (netlifyConfig.functions[HANDLER_FUNCTION_NAME].included_files = [])
netlifyConfig.functions[ODB_FUNCTION_NAME] && (netlifyConfig.functions[ODB_FUNCTION_NAME].included_files = [])
Expand All @@ -88,7 +90,6 @@ beforeEach(async () => {
afterEach(async () => {
jest.clearAllMocks()
jest.resetAllMocks()
delete process.env.NEXT_PRIVATE_TARGET
// Cleans up the temporary directory from `getTmpDir()` and do not make it
// the current directory anymore
restoreCwd()
Expand Down Expand Up @@ -133,6 +134,13 @@ describe('preBuild()', () => {

expect(restore).toHaveBeenCalledWith(path.posix.resolve('.next/cache'))
})

it('forces the target to "server"', async () => {
const netlifyConfig = { ...defaultArgs.netlifyConfig }

await plugin.onPreBuild({ ...defaultArgs, netlifyConfig })
expect(netlifyConfig.build.environment.NEXT_PRIVATE_TARGET).toBe('server')
})
})

describe('onBuild()', () => {
Expand Down