@@ -2,6 +2,7 @@ const { yellowBright } = require('chalk')
2
2
const { lt : ltVersion , gte : gteVersion } = require ( 'semver' )
3
3
4
4
const getNextRoot = require ( './getNextRoot' )
5
+ const resolveNextModule = require ( './resolveNextModule' )
5
6
6
7
// Ensure Next.js is available.
7
8
// We use `peerDependencies` instead of `dependencies` so that users can choose
@@ -10,20 +11,17 @@ const getNextRoot = require('./getNextRoot')
10
11
const validateNextUsage = function ( { failBuild, netlifyConfig } ) {
11
12
const nextRoot = getNextRoot ( { netlifyConfig } )
12
13
// Because we don't know the monorepo structure, we try to resolve next both locally and in the next root
13
- const paths = [ nextRoot , process . cwd ( ) ]
14
- if ( ! hasPackage ( 'next' , paths ) ) {
14
+ if ( ! hasPackage ( 'next' , nextRoot ) ) {
15
15
return failBuild (
16
- ' This site does not seem to be using Next.js. Please run "npm install next" or "yarn next" in the repository.' ,
16
+ ` This site does not seem to be using Next.js. Please run "npm install next" or "yarn next" in the repository. ${ nextRoot } ${ process . cwd ( ) } ` ,
17
17
)
18
18
}
19
19
20
20
// We cannot load `next` at the top-level because we validate whether the
21
21
// site is using `next` inside `onPreBuild`.
22
22
// Old Next.js versions are not supported
23
- // eslint-disable-next-line node/no-unpublished-require
24
- const pkg = require . resolve ( `next/package.json` , { paths } )
25
23
// eslint-disable-next-line import/no-dynamic-require
26
- const { version } = require ( pkg )
24
+ const { version } = require ( resolveNextModule ( `next/package.json` , nextRoot ) )
27
25
if ( ltVersion ( version , MIN_VERSION ) ) {
28
26
return failBuild ( `Please upgrade to Next.js ${ MIN_VERSION } or later. Found ${ version } .` )
29
27
}
@@ -39,9 +37,9 @@ const validateNextUsage = function ({ failBuild, netlifyConfig }) {
39
37
const MIN_VERSION = '10.0.6'
40
38
const MIN_EXPERIMENTAL_VERSION = '11.0.0'
41
39
42
- const hasPackage = function ( packageName , paths ) {
40
+ const hasPackage = function ( packageName , nextRoot ) {
43
41
try {
44
- require . resolve ( `${ packageName } /package.json` , { paths } )
42
+ resolveNextModule ( `${ packageName } /package.json` , nextRoot )
45
43
return true
46
44
} catch ( error ) {
47
45
return false
0 commit comments