Skip to content

Commit 01fa113

Browse files
authored
fix: disable serverless targets (#739)
1 parent ef2da0d commit 01fa113

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ publish = ".next"
3131
package = "@netlify/plugin-nextjs"
3232
```
3333

34-
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.
34+
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.
35+
36+
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.
3537

3638
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.
3739

src/helpers/verification.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ const outdent = require('outdent')
88
const prettyBytes = require('pretty-bytes')
99
const { satisfies } = require('semver')
1010

11-
exports.verifyBuildTarget = (target) => {
12-
if (target !== 'server') {
13-
console.log(
14-
yellowBright`Setting target to ${target} is no longer required. You should check if target=server works for you.`,
15-
)
16-
}
17-
}
18-
1911
// This is when nft support was added
2012
const REQUIRED_BUILD_VERSION = '>=18.16.0'
2113

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const { generateFunctions, setupImageFunction, generatePagesResolver } = require
1212
const {
1313
verifyNetlifyBuildVersion,
1414
checkNextSiteHasBuilt,
15-
verifyBuildTarget,
1615
checkForRootPublish,
1716
logBetaMessage,
1817
checkZipSize,
@@ -33,6 +32,10 @@ module.exports = {
3332
verifyNetlifyBuildVersion({ failBuild, ...constants })
3433

3534
await restoreCache({ cache, publish })
35+
36+
netlifyConfig.build.environment ||= {}
37+
// eslint-disable-next-line unicorn/consistent-destructuring
38+
netlifyConfig.build.environment.NEXT_PRIVATE_TARGET = 'server'
3639
},
3740

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

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

51-
verifyBuildTarget(target)
52-
5354
configureHandlerFunctions({ netlifyConfig, ignore, publish: relative(process.cwd(), publish) })
5455

5556
await generateFunctions(constants, appDir)

test/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ beforeEach(async () => {
7979
cleanup = tmpDir.cleanup
8080

8181
netlifyConfig.build.publish = path.posix.resolve('.next')
82+
netlifyConfig.build.environment = {}
83+
8284
netlifyConfig.redirects = []
8385
netlifyConfig.functions[HANDLER_FUNCTION_NAME] && (netlifyConfig.functions[HANDLER_FUNCTION_NAME].included_files = [])
8486
netlifyConfig.functions[ODB_FUNCTION_NAME] && (netlifyConfig.functions[ODB_FUNCTION_NAME].included_files = [])
@@ -88,7 +90,6 @@ beforeEach(async () => {
8890
afterEach(async () => {
8991
jest.clearAllMocks()
9092
jest.resetAllMocks()
91-
delete process.env.NEXT_PRIVATE_TARGET
9293
// Cleans up the temporary directory from `getTmpDir()` and do not make it
9394
// the current directory anymore
9495
restoreCwd()
@@ -133,6 +134,13 @@ describe('preBuild()', () => {
133134

134135
expect(restore).toHaveBeenCalledWith(path.posix.resolve('.next/cache'))
135136
})
137+
138+
it('forces the target to "server"', async () => {
139+
const netlifyConfig = { ...defaultArgs.netlifyConfig }
140+
141+
await plugin.onPreBuild({ ...defaultArgs, netlifyConfig })
142+
expect(netlifyConfig.build.environment.NEXT_PRIVATE_TARGET).toBe('server')
143+
})
136144
})
137145

138146
describe('onBuild()', () => {

0 commit comments

Comments
 (0)