Skip to content

Commit 106a177

Browse files
authored
Merge pull request #124 from netlify/fix/get-next-config
fix: fix errors while loading `next.config.js`
2 parents 2ee1c38 + e55f2a9 commit 106a177

7 files changed

+14
-23
lines changed

helpers/doesNotNeedPlugin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ const isStaticExportProject = require('./isStaticExportProject')
55
const doesSiteUseNextOnNetlify = require('./doesSiteUseNextOnNetlify')
66
const hasCorrectNextConfig = require('./hasCorrectNextConfig')
77

8-
const doesNotNeedPlugin = async ({ netlifyConfig, packageJson, utils }) => {
8+
const doesNotNeedPlugin = async ({ netlifyConfig, packageJson, failBuild }) => {
99
const { build } = netlifyConfig
1010
const { name, scripts = {} } = packageJson
1111
const nextConfigPath = await findUp('next.config.js')
1212

1313
return (
1414
isStaticExportProject({ build, scripts }) ||
1515
doesSiteUseNextOnNetlify({ packageJson }) ||
16-
!(await hasCorrectNextConfig({ nextConfigPath, failBuild: utils.build.failBuild }))
16+
!(await hasCorrectNextConfig({ nextConfigPath, failBuild }))
1717
)
1818
}
1919

helpers/getNextConfig.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { resolve } = require('path')
33
let nextConfig
44

55
// Load next.config.js
6-
const getNextConfig = async function (failBuild) {
6+
const getNextConfig = async function (failBuild = defaultFailBuild) {
77
// Memoizes `nextConfig`
88
if (nextConfig !== undefined) {
99
return nextConfig
@@ -23,4 +23,8 @@ const getNextConfig = async function (failBuild) {
2323
return nextConfig
2424
}
2525

26+
const defaultFailBuild = function (message, { error }) {
27+
throw new Error(`${message}\n${error.stack}`)
28+
}
29+
2630
module.exports = getNextConfig

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
return failBuild('Could not find a package.json for this project')
2626
}
2727

28-
if (await doesNotNeedPlugin({ netlifyConfig, packageJson, utils })) {
28+
if (await doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })) {
2929
return
3030
}
3131

@@ -46,7 +46,9 @@ module.exports = {
4646
constants: { PUBLISH_DIR, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC },
4747
utils,
4848
}) {
49-
if (await doesNotNeedPlugin({ netlifyConfig, packageJson, utils })) {
49+
const { failBuild } = utils.build
50+
51+
if (await doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })) {
5052
return
5153
}
5254

src/lib/helpers/getI18n.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Get the i1i8n details specified in next.config.js, if any
2-
const getNextConfig = require('./getNextConfig')
2+
const getNextConfig = require('../../../helpers/getNextConfig')
33

44
const getI18n = async () => {
55
const nextConfig = await getNextConfig()

src/lib/helpers/getNextConfig.js

-15
This file was deleted.

src/lib/helpers/getNextDistDir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Get the NextJS distDir specified in next.config.js
22
const { join } = require('path')
3-
const getNextConfig = require('./getNextConfig')
3+
const getNextConfig = require('../../../helpers/getNextConfig')
44

55
const getNextDistDir = async () => {
66
const nextConfig = await getNextConfig()

src/lib/helpers/getPrerenderManifest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { join } = require('path')
22
const { readJSONSync } = require('fs-extra')
3-
const getNextConfig = require('./getNextConfig')
3+
const getNextConfig = require('../../../helpers/getNextConfig')
44
const getNextDistDir = require('./getNextDistDir')
55
const getDataRouteForRoute = require('./getDataRouteForRoute')
66
const asyncForEach = require('./asyncForEach')

0 commit comments

Comments
 (0)