anomalyco/sst · warning
Failed to detect Next.js version. Using OpenNext v${DEFAULT_
Error message
Failed to detect Next.js version. Using OpenNext v${DEFAULT_OPEN_NEXT_VERSION} as default. What it means
The Nextjs component inspects package.json to decide whether to use OpenNext v2 (Next.js 14) or the default OpenNext version. When the package.json cannot be read or parsed (or `next` cannot be resolved from dependencies/devDependencies), detectDefaultOpenNextVersion logs this console.warn and falls back to the default OpenNext version rather than failing the deploy.
Source
Thrown at platform/src/components/aws/nextjs.ts:596
super(__pulumiType, name, args, opts);
}
protected normalizeBuildCommand(args: NextjsArgs) {
return all([args?.buildCommand, args?.openNextVersion, args?.path]).apply(
([buildCommand, openNextVersion, sitePath]) => {
if (buildCommand) return buildCommand;
function detectDefaultOpenNextVersion() {
try {
const pkgPath = path.join(sitePath ?? ".", "package.json");
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
const nextVersion =
pkg.dependencies?.next ?? pkg.devDependencies?.next;
if (nextVersion && isALtB(nextVersion, "15.0.0")) {
return DEFAULT_OPEN_NEXT_VERSION_NEXT14;
}
} catch {
console.warn(`Failed to detect Next.js version. Using OpenNext v${DEFAULT_OPEN_NEXT_VERSION} as default.`);
}
return DEFAULT_OPEN_NEXT_VERSION;
}
const version = openNextVersion ?? detectDefaultOpenNextVersion();
const packageName = isALteB(version, "3.1.3")
? "open-next"
: "@opennextjs/aws";
return `npx --yes ${packageName}@${version} build`;
},
);
}
protected buildPlan(
outputPath: Output<string>,
name: string,
args: NextjsArgs,
{ bucket }: { bucket: Bucket },View on GitHub (pinned to a0bd20f762)
Solutions
- Verify the component's `path`/`root` points to the directory containing the Next.js app's package.json
- Ensure the app has `next` listed in dependencies (or devDependencies) with a valid semver version (e.g. "15.1.0") — replace placeholders like `workspace:*` or `file:` specs
- Fix any JSON syntax errors in package.json (`npx jsonlint package.json` or `cat package.json | node -e 'JSON.parse(require("fs").readFileSync(0))'`)
- Pin the OpenNext version explicitly: `sst nextjs.Nextjs(..., { openNextVersion: "3.x.x" })` to skip auto-detection and silence the warning
Example fix
// before (sst.config.ts, path misconfigured)
new sst.aws.Nextjs("Web", { path: "packages/webapp" }) // no package.json there
// after
new sst.aws.Nextjs("Web", { path: "apps/web" }) // apps/web/package.json has "next": "15.1.0" Defensive patterns
Strategy: validation
Validate before calling
const pkg = JSON.parse(fs.readFileSync(path.join(appPath, "package.json"), "utf8"));
const next = pkg.dependencies?.next ?? pkg.devDependencies?.next;
if (!next || !semver.valid(semver.coerce(next))) {
throw new Error(`package.json at ${appPath} has no valid semver "next" dependency; got: ${next}`);
} Type guard
function isValidNextVersion(v: unknown): v is string {
return typeof v === "string" && /^(\^|~|>=?)?\d+\.\d+\.\d+/.test(v) && !v.startsWith("workspace:") && !v.startsWith("file:");
} Try / catch
try {
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
// use pkg.dependencies?.next
} catch (err) {
console.warn(`Failed to detect Next.js version (${err}); set openNextVersion explicitly in sst.config.ts`);
return DEFAULT_OPEN_NEXT_VERSION;
} Prevention
- Pin `next` to an explicit semver version in package.json — avoid workspace:/file:/latest specs
- Set `openNextVersion` explicitly on the Nextjs component to bypass auto-detection
- Confirm the component's `path` points at the folder containing package.json
- Keep package.json valid JSON and committed to the deploy context (not gitignored)
When it happens
Trigger: Calling sst nextjs component construction (openNextVersion not explicitly set) while the app's package.json is missing, unreadable, malformed JSON, lacks a `next` entry in dependencies/devDependencies, or uses a non-semver `next` version string that breaks isALtB comparison inside the try block.
Common situations: Deploying a Next.js app whose package.json was not included (wrong `root`/`path` config pointing at a directory without package.json); monorepo paths misconfigured; a `next` version like `workspace:*` or a file: URL that the semver comparator rejects; deploying a Next.js 15+ app (returns default path but the catch still fires on parse issues).
Related errors
- Lambda@Edge runtime is deprecated. Update your OpenNext conf
- Could not load OpenNext output file at "${openNextOutputPath
- Build ID not found in ".next/BUILD_ID" for site "${name}". E
- Base path configuration not found in ".next/routes-manifest.
- failed to create DNS record, status: %d, response: %s
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/ed87d0d58b18022b.
Report an issue: GitHub.