diff --git a/packages/runtime/src/helpers/functionsMetaData.ts b/packages/runtime/src/helpers/functionsMetaData.ts index 477a88f0b7..4e22c8653d 100644 --- a/packages/runtime/src/helpers/functionsMetaData.ts +++ b/packages/runtime/src/helpers/functionsMetaData.ts @@ -18,7 +18,7 @@ const getNextRuntimeVersion = async (packageJsonPath: string, useNodeModulesPath const PLUGIN_PACKAGE_PATH = '.netlify/plugins/package.json' -const nextPluginVersion = async (module?: string) => { +export const nextPluginVersion = async (module?: string) => { const moduleRoot = resolveModuleRoot(module || NEXT_PLUGIN) const nodeModulesPath = moduleRoot ? join(moduleRoot, 'package.json') : null diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 7dca0b8c9e..88e01ea7b5 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -5,6 +5,7 @@ import { bold, redBright } from 'chalk' import destr from 'destr' import { existsSync, readFileSync } from 'fs-extra' import { outdent } from 'outdent' +import { satisfies } from 'semver' import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME } from './constants' import { restoreCache, saveCache } from './helpers/cache' @@ -30,6 +31,7 @@ import { APILambda, getSSRLambdas, } from './helpers/functions' +import { nextPluginVersion } from './helpers/functionsMetaData' import { generateRedirects, generateStaticRedirects } from './helpers/redirects' import { shouldSkip, @@ -79,6 +81,12 @@ const plugin: NetlifyPlugin = { checkForRootPublish({ publish, failBuild }) verifyNetlifyBuildVersion({ failBuild, ...constants }) + const nextVersion = await nextPluginVersion('next') + if (!satisfies(nextVersion, '< 13.5')) { + failBuild('NextJS 13.5 and newer is not yet supported.') + return + } + await restoreCache({ cache, publish }) netlifyConfig.build.environment ||= {}