{"record":{"id":"1473b1ba0c630b81","repo":"vitejs/vite","slug":"cannot-deep-clone-non-plain-object","errorCode":null,"errorMessage":"Cannot deep clone non-plain object","messagePattern":"Cannot deep clone non-plain object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/utils.ts","lineNumber":1231,"sourceCode":"export function deepClone<T>(value: T): DeepWritable<T> {\n  if (Array.isArray(value)) {\n    return value.map((v) => deepClone(v)) as DeepWritable<T>\n  }\n  if (isObject(value)) {\n    const cloned: Record<string, any> = {}\n    for (const key in value) {\n      cloned[key] = deepClone(value[key])\n    }\n    return cloned as DeepWritable<T>\n  }\n  if (typeof value === 'function') {\n    return value as DeepWritable<T>\n  }\n  if (value instanceof RegExp) {\n    return new RegExp(value) as DeepWritable<T>\n  }\n  if (typeof value === 'object' && value != null) {\n    throw new Error('Cannot deep clone non-plain object')\n  }\n  return value as DeepWritable<T>\n}\n\ntype MaybeFallback<D, V> = undefined extends V ? Exclude<V, undefined> | D : V\n\ntype MergeWithDefaultsResult<D, V> =\n  Equal<D, undefined> extends true\n    ? V\n    : D extends Function | Array<any>\n      ? MaybeFallback<D, V>\n      : V extends Function | Array<any>\n        ? MaybeFallback<D, V>\n        : D extends Record<string, any>\n          ? V extends Record<string, any>\n            ? {\n                [K in keyof D | keyof V]: K extends keyof D\n                  ? K extends keyof V","sourceCodeStart":1213,"sourceCodeEnd":1249,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/utils.ts#L1213-L1249","documentation":"Thrown by deepClone() for a value that is an object (typeof 'object', non-null) but is not an array, not a plain {Object} (Object.prototype.toString !== '[object Object]'), not a function, and not a RegExp. deepClone only knows how to structurally copy plain data; instances of Date, Map, Set, Error, class instances, etc. are rejected rather than silently mishandled.","triggerScenarios":"Passing a config/value containing a Date, Map, Set, Error, Promise, ArrayBuffer, TypedArray, URL, or any class instance to deepClone(). The fallthrough branch at utils.ts:1230-1232 catches all other object types.","commonSituations":"deepClone is used internally when cloning resolved config / user options; passing a non-serializable value (e.g. a Date in a plugin option, a Map for aliases, a class instance) triggers it. Calling deepClone directly on plugin state that holds instances.","solutions":["Convert non-plain values to plain equivalents before cloning (Date -> ISO string / number, Map -> plain object, Set -> array).","Avoid putting class instances or built-in non-plain objects into config that Vite will deep-clone.","If you call deepClone yourself, restrict inputs to JSON-shaped data (objects, arrays, primitives, RegExp)."],"exampleFix":"// before\nconst cfg = { lastBuilt: new Date() }\ndeepClone(cfg) // throws\n// after\nconst cfg = { lastBuilt: Date.now() }\ndeepClone(cfg) // ok","handlingStrategy":"type-guard","validationCode":"function isDeepCloneable(v: unknown): boolean {\n  if (v == null || typeof v !== 'object') return true\n  if (Array.isArray(v)) return v.every(isDeepCloneable)\n  if (Object.prototype.toString.call(v) === '[object Object]')\n    return Object.values(v).every(isDeepCloneable)\n  return v instanceof RegExp || typeof v === 'function'\n}","typeGuard":"function isPlainCloneable(v: unknown): boolean {\n  if (v == null) return true\n  if (typeof v !== 'object') return true\n  if (Array.isArray(v)) return true\n  if (Object.prototype.toString.call(v) === '[object Object]') return true\n  if (v instanceof RegExp) return true\n  return false\n}","tryCatchPattern":null,"preventionTips":["Keep config values JSON-shaped; convert Date/Map/Set to primitives before passing to Vite.","Don't embed class instances in plugin options that Vite will clone."],"tags":["utils","serialization","configuration"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}