@@ -2,6 +2,7 @@ const { readdirSync, existsSync } = require('fs')
2
2
const path = require ( 'path' )
3
3
4
4
const makeDir = require ( 'make-dir' )
5
+ const { satisfies } = require ( 'semver' )
5
6
6
7
const { restoreCache, saveCache } = require ( './helpers/cacheBuild' )
7
8
const checkNxConfig = require ( './helpers/checkNxConfig' )
@@ -12,12 +13,16 @@ const getNextRoot = require('./helpers/getNextRoot')
12
13
const validateNextUsage = require ( './helpers/validateNextUsage' )
13
14
const verifyBuildTarget = require ( './helpers/verifyBuildTarget' )
14
15
const nextOnNetlify = require ( './src' )
16
+
17
+ // This is when the esbuild dynamic import support was added
18
+ const REQUIRED_BUILD_VERSION = '>=15.11.5'
19
+
15
20
// * Helpful Plugin Context *
16
21
// - Between the prebuild and build steps, the project's build command is run
17
22
// - Between the build and postbuild steps, any functions are bundled
18
23
19
24
module . exports = {
20
- async onPreBuild ( { netlifyConfig, packageJson, utils, constants } ) {
25
+ async onPreBuild ( { netlifyConfig, packageJson, utils, constants = { } } ) {
21
26
const { failBuild } = utils . build
22
27
23
28
validateNextUsage ( { failBuild, netlifyConfig } )
@@ -30,6 +35,13 @@ module.exports = {
30
35
if ( doesNotNeedPlugin ( { netlifyConfig, packageJson, failBuild } ) ) {
31
36
return
32
37
}
38
+ // We check for build version because that's what's available to us, but prompt about the cli because that's what they can upgrade
39
+ if ( constants . IS_LOCAL && ! satisfies ( constants . NETLIFY_BUILD_VERSION , REQUIRED_BUILD_VERSION ) ) {
40
+ return failBuild (
41
+ `This version of the Essential Next.js plugin requires [email protected] or higher. Please upgrade and try again.
42
+ You can do this by running: "npm install -g netlify-cli@latest" or "yarn global add netlify-cli@latest"` ,
43
+ )
44
+ }
33
45
34
46
// Populates the correct config if needed
35
47
await verifyBuildTarget ( { netlifyConfig, packageJson, failBuild } )
@@ -71,14 +83,15 @@ module.exports = {
71
83
}
72
84
console . log ( 'Detected Next.js site. Copying files...' )
73
85
74
- const { distDir } = await getNextConfig ( failBuild , nextRoot )
75
-
86
+ const { distDir, configFile } = await getNextConfig ( failBuild , nextRoot )
76
87
const dist = path . resolve ( nextRoot , distDir )
88
+
77
89
if ( ! existsSync ( dist ) ) {
78
90
failBuild ( `
79
- Could not find "${ distDir } " after building the site, which indicates that "next build" was not run.
80
- Check that your build command includes "next build". If the site is a monorepo, see https://ntl.fyi/next-monorepo
81
- for information on configuring the site. If this is not a Next.js site you should remove the Essential Next.js plugin.
91
+ Could not find "${ distDir } " after building the site, which indicates that "next build" was not run or that we're looking in the wrong place.
92
+ We're using the config file ${ configFile } , and looking for the dist directory at ${ dist } . If this is incorrect, try deleting the config file, or
93
+ moving it to the correct place. Check that your build command includes "next build". If the site is a monorepo, see https://ntl.fyi/next-monorepo
94
+ for information on configuring the site. If this is not a Next.js site, or if it uses static export, you should remove the Essential Next.js plugin.
82
95
See https://ntl.fyi/remove-plugin for instructions.
83
96
` )
84
97
}
0 commit comments