Summary
new.target is undefined inside the constructor of a class X extends Error declared inside a CJS module function (webpack-wrapper shape). Reading new.target.prototype throws.
This is the residual error-path blocker behind #6530: with the #6530 family fixed, Next.js's config-schema.js initializes and configSchema.safeParse(<valid config>) matches node — but any validation failure constructs the bundled zod's ZodError, whose constructor does const t = new.target.prototype → TypeError: Cannot read properties of undefined (reading 'prototype') (in the reduced repro below the message is undefined is not a constructor).
Repro
nt_err.cjs:
(() => {
"use strict";
var mods = {
7: function (e, t) {
class MyErr extends Error {
constructor(issues) {
super();
this.issues = [];
const p = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, p);
this.name = "MyErr";
this.issues = issues;
}
}
t.MyErr = MyErr;
},
};
var cache = {};
function req(id) {
if (cache[id]) return cache[id].exports;
var m = (cache[id] = { exports: {} });
mods[id].call(m.exports, m, m.exports);
return m.exports;
}
module.exports = req(7);
})();
nt_err.ts:
const m = require("./nt_err.cjs");
const e = new m.MyErr([{ code: "x" }]);
console.log("name:", e.name, "issues:", JSON.stringify(e.issues));
node: name: MyErr issues: [{"code":"x"}]
perry: TypeError: undefined is not a constructor
Notes
Summary
new.targetisundefinedinside the constructor of aclass X extends Errordeclared inside a CJS module function (webpack-wrapper shape). Readingnew.target.prototypethrows.This is the residual error-path blocker behind #6530: with the #6530 family fixed, Next.js's
config-schema.jsinitializes andconfigSchema.safeParse(<valid config>)matches node — but any validation failure constructs the bundled zod'sZodError, whose constructor doesconst t = new.target.prototype→TypeError: Cannot read properties of undefined (reading 'prototype')(in the reduced repro below the message isundefined is not a constructor).Repro
nt_err.cjs:nt_err.ts:node:
name: MyErr issues: [{"code":"x"}]perry:
TypeError: undefined is not a constructorNotes
ctor_chain_uses_new_targetgatesjs_new_target_setaround the standalone-symbol ctor call inlower_call/new.rs), but the Error-subclass construction path for a CJS-nested class apparently never arms the cell.ZodErroris the production hit: everysafeParsefailure of Next's bundled zod constructs it, so invalidnext.config.jsvalues crash instead of reporting issues.