File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 1
1
const { resolve } = require ( 'path' )
2
2
3
- let nextConfig
4
-
5
3
// Load next.config.js
6
4
const getNextConfig = async function ( failBuild = defaultFailBuild ) {
5
+ try {
6
+ return await getNextConfigValue ( )
7
+ } catch ( error ) {
8
+ return failBuild ( 'Error loading your next.config.js.' , { error } )
9
+ }
10
+ }
11
+
12
+ let nextConfigPromise
13
+
14
+ const getNextConfigValue = function ( ) {
7
15
// Memoizes `nextConfig`
8
- if ( nextConfig !== undefined ) {
9
- return nextConfig
16
+ if ( nextConfigPromise !== undefined ) {
17
+ return nextConfigPromise
10
18
}
11
19
12
20
// We cannot load `next` at the top-level because we validate whether the
13
21
// site is using `next` inside `onPreBuild`.
14
22
const { PHASE_PRODUCTION_BUILD } = require ( 'next/constants' )
15
23
const loadConfig = require ( 'next/dist/next-server/server/config' ) . default
16
24
17
- try {
18
- nextConfig = await loadConfig ( PHASE_PRODUCTION_BUILD , resolve ( '.' ) )
19
- } catch ( error ) {
20
- return failBuild ( 'Error loading your next.config.js.' , { error } )
21
- }
22
-
23
- return nextConfig
25
+ nextConfigPromise = loadConfig ( PHASE_PRODUCTION_BUILD , resolve ( '.' ) )
26
+ return nextConfigPromise
24
27
}
25
28
26
29
const defaultFailBuild = function ( message , { error } ) {
You can’t perform that action at this time.
0 commit comments