@@ -3,13 +3,12 @@ const path = require('path')
3
3
const util = require ( 'util' )
4
4
5
5
const nextOnNetlify = require ( 'next-on-netlify' )
6
- const { PHASE_PRODUCTION_BUILD } = require ( 'next/constants' )
7
- const { default : loadConfig } = require ( 'next/dist/next-server/server/config' )
8
6
const findUp = require ( 'find-up' )
9
7
const makeDir = require ( 'make-dir' )
10
8
const { copy } = require ( 'cpx' )
11
9
12
10
const isStaticExportProject = require ( './helpers/isStaticExportProject' )
11
+ const { validateNextUsage } = require ( './helpers/validateNextUsage' )
13
12
14
13
const pWriteFile = util . promisify ( fs . writeFile )
15
14
const pCopy = util . promisify ( copy )
@@ -22,6 +21,8 @@ module.exports = {
22
21
async onPreBuild ( { netlifyConfig, packageJson, utils } ) {
23
22
const { failBuild } = utils . build
24
23
24
+ validateNextUsage ( failBuild )
25
+
25
26
if ( Object . keys ( packageJson ) . length === 0 ) {
26
27
return failBuild ( `Could not find a package.json for this project` )
27
28
}
@@ -46,6 +47,11 @@ module.exports = {
46
47
47
48
const nextConfigPath = await findUp ( 'next.config.js' )
48
49
if ( nextConfigPath !== undefined ) {
50
+ // We cannot load `next` at the top-level because we validate whether the
51
+ // site is using `next` inside `onPreBuild`.
52
+ const { PHASE_PRODUCTION_BUILD } = require ( 'next/constants' )
53
+ const { default : loadConfig } = require ( 'next/dist/next-server/server/config' )
54
+
49
55
// If the next config exists, fail build if target isnt in acceptableTargets
50
56
const acceptableTargets = [ 'serverless' , 'experimental-serverless-trace' ]
51
57
const nextConfig = loadConfig ( PHASE_PRODUCTION_BUILD , path . resolve ( '.' ) )
@@ -66,6 +72,7 @@ module.exports = {
66
72
} ,
67
73
async onBuild ( { constants : { PUBLISH_DIR , FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC } } ) {
68
74
console . log ( `** Running Next on Netlify package **` )
75
+
69
76
nextOnNetlify ( )
70
77
71
78
// Next-on-netlify puts its files into out_functions and out_publish
0 commit comments