diff --git a/package.json b/package.json index 1418906a..6f0e6cff 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "cross-spawn": "5.1.0", "del": "3.0.0", "etag": "1.8.1", + "find-up": "2.1.0", "fresh": "0.5.2", "friendly-errors-webpack-plugin": "1.6.1", "glob": "7.1.2", diff --git a/server/config.js b/server/config.js index 10fcddd3..395b92c5 100644 --- a/server/config.js +++ b/server/config.js @@ -1,5 +1,4 @@ -import { join } from 'path' -import { existsSync } from 'fs' +import findUp from 'find-up' const cache = new Map() @@ -26,12 +25,13 @@ function loadConfig (dir, customConfig) { customConfig.configOrigin = 'server' return withDefaults(customConfig) } - const path = join(dir, 'next.config.js') + const path = findUp.sync('next.config.js', { + cwd: dir + }) let userConfig = {} - const userHasConfig = existsSync(path) - if (userHasConfig) { + if (path && path.length) { const userConfigModule = require(path) userConfig = userConfigModule.default || userConfigModule userConfig.configOrigin = 'next.config.js'