diff --git a/packages/next/server/config.ts b/packages/next/server/config.ts index 9893bda9ddea69..8f1746bbf24f9e 100644 --- a/packages/next/server/config.ts +++ b/packages/next/server/config.ts @@ -44,6 +44,24 @@ const experimentalWarning = execOnce( } ) +const notExistedExperimentalFeatureWarning = execOnce( + (configFileName: string, features: string[]) => { + const s = features.length > 1 ? 's' : '' + const dont = features.length > 1 ? 'do not' : 'does not' + const exist = features.length > 1 ? 'exist' : 'exists' + const them = features.length > 1 ? 'them' : 'it' + Log.warn( + chalk.bold( + `You have defined experimental feature${s} (${features.join( + ', ' + )}) in ${configFileName} that ${dont} ${exist} in this version of Next.js.` + ) + ) + Log.warn(`Please remove ${them} from your configuration.`) + console.warn() + } +) + function assignDefaults(userConfig: { [key: string]: any }) { const configFileName = userConfig.configFileName if (typeof userConfig.exportTrailingSlash !== 'undefined') { @@ -79,16 +97,29 @@ function assignDefaults(userConfig: { [key: string]: any }) { } if (key === 'experimental' && typeof value === 'object') { - const enabledExperimentalFeatures = ( - Object.keys(value) as (keyof ExperimentalConfig)[] - ).filter( - // defaultConfig is pre-defined, thus defaultConfig.experimental can not be undefined - (featureName) => + const notExistedExperimentalFeatures: string[] = [] + const enabledExperimentalFeatures: (keyof ExperimentalConfig)[] = [] + + for (const featureName of Object.keys( + value + ) as (keyof ExperimentalConfig)[]) { + if (!(featureName in defaultConfig.experimental!)) { + notExistedExperimentalFeatures.push(featureName) + } else if ( value[featureName] !== defaultConfig.experimental![featureName] - ) + ) { + enabledExperimentalFeatures.push(featureName) + } + } + if (notExistedExperimentalFeatures.length > 0) { + notExistedExperimentalFeatureWarning( + configFileName, + notExistedExperimentalFeatures + ) + } if (enabledExperimentalFeatures.length > 0) { - experimentalWarning(configFileName, Object.keys(value)) + experimentalWarning(configFileName, enabledExperimentalFeatures) } }