@@ -25,19 +25,19 @@ export function normalizeOptions(config: OpenNextConfig, root: string) {
25
25
) ;
26
26
const outputDir = path . join ( buildOutputPath , ".open-next" ) ;
27
27
28
- let nextPackageJsonPath : string ;
28
+ let appPackageJsonPath : string ;
29
29
if ( config . packageJsonPath ) {
30
30
const _pkgPath = path . join ( process . cwd ( ) , config . packageJsonPath ) ;
31
- nextPackageJsonPath = _pkgPath . endsWith ( "package.json" )
31
+ appPackageJsonPath = _pkgPath . endsWith ( "package.json" )
32
32
? _pkgPath
33
33
: path . join ( _pkgPath , "./package.json" ) ;
34
34
} else {
35
- nextPackageJsonPath = findNextPackageJsonPath ( appPath , root ) ;
35
+ appPackageJsonPath = findNextPackageJsonPath ( appPath , root ) ;
36
36
}
37
37
return {
38
38
openNextVersion : getOpenNextVersion ( ) ,
39
- nextVersion : getNextVersion ( nextPackageJsonPath ) ,
40
- nextPackageJsonPath ,
39
+ nextVersion : getNextVersion ( appPath ) ,
40
+ appPackageJsonPath ,
41
41
appPath,
42
42
appBuildOutputPath : buildOutputPath ,
43
43
appPublicPath : path . join ( appPath , "public" ) ,
@@ -209,9 +209,12 @@ export function getOpenNextVersion(): string {
209
209
return require ( path . join ( __dirname , "../../package.json" ) ) . version ;
210
210
}
211
211
212
- export function getNextVersion ( nextPackageJsonPath : string ) : string {
213
- const version = require ( nextPackageJsonPath ) ?. dependencies ?. next ;
214
- // require('next/package.json').version
212
+ export function getNextVersion ( appPath : string ) : string {
213
+ // We cannot just require("next/package.json") because it could be executed in a different directory
214
+ const nextPackageJsonPath = require . resolve ( "next/package.json" , {
215
+ paths : [ appPath ] ,
216
+ } ) ;
217
+ const version = require ( nextPackageJsonPath ) ?. version ;
215
218
216
219
if ( ! version ) {
217
220
throw new Error ( "Failed to find Next version" ) ;
0 commit comments