{"record":{"id":"685a68686adb9a66","repo":"zloirock/core-js","slug":"promise-can-t-be-resolved-itself","errorCode":null,"errorMessage":"Promise can't be resolved itself","messagePattern":"Promise can't be resolved itself","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/es.promise.constructor.js","lineNumber":173,"sourceCode":"    fn(state, value, unwrap);\n  };\n};\n\nvar internalReject = function (state, value, unwrap) {\n  if (state.done) return;\n  state.done = true;\n  if (unwrap) state = unwrap;\n  state.value = value;\n  state.state = REJECTED;\n  notify(state, true);\n};\n\nvar internalResolve = function (state, value, unwrap) {\n  if (state.done) return;\n  state.done = true;\n  if (unwrap) state = unwrap;\n  try {\n    if (state.facade === value) throw new TypeError(\"Promise can't be resolved itself\");\n    var then = isThenable(value);\n    if (then) {\n      microtask(function () {\n        var wrapper = { done: false };\n        try {\n          call(then, value,\n            bind(internalResolve, wrapper, state),\n            bind(internalReject, wrapper, state)\n          );\n        } catch (error) {\n          internalReject(wrapper, error, state);\n        }\n      });\n    } else {\n      state.value = value;\n      state.state = FULFILLED;\n      notify(state, false);\n    }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/es.promise.constructor.js#L155-L191","documentation":"core-js's Promise polyfill rejects a promise being resolved with its own fulfillment value/thenable wrapper. Per spec, resolving a promise with itself would create an unresolvable cycle, so internalResolve detects state.facade === value and throws a TypeError. This can also surface via Promise.all/then chains that feed a promise back into itself.","triggerScenarios":"const p = new Promise(res => res(p)); — resolving a promise with itself; promise.then(resolve) wired so the resolution value is the same promise; circular thenable structures where a promise's fulfillment value is the promise object; polyfilled Promise.all/settled input arrays containing the aggregate promise itself.","commonSituations":"Recursive async code caching a promise and passing it to its own resolve callback; refactoring a callback API where the resolve reference and the returned promise are the same variable; Promise.all(promiseItself) by mistake; using a polyfilled Promise (older browsers) where native engines may report 'Chaining cycle detected'.","solutions":["Never resolve a promise with itself; verify the value passed to resolve() is not the promise variable (rename variables to avoid shadowing).","Resolve with the underlying value instead of the promise: fetch the awaited data and pass that.","Break the circular reference: if a thenable references its container, unwrap it before resolving.","If using polyfilled Promise in tests, replicate the cycle check — it's spec behavior, not a bug.","Return the promise from the executor rather than resolving it (let the chain propagate)."],"exampleFix":"// before\nconst p = new Promise((resolve) => {\n  doWork((err, result) => resolve(result ?? p)); // TypeError when result missing\n});\n// after\nconst p = new Promise((resolve) => {\n  doWork((err, result) => resolve(result));\n});","handlingStrategy":"validation","validationCode":"function safeResolve(promiseRef, value) {\n  if (value === promiseRef || (value && typeof value.then === 'function' && value === promiseRef)) {\n    throw new TypeError('Cannot resolve a promise with itself');\n  }\n}\n// call before: safeResolve(p, candidateValue)","typeGuard":"function isSelfResolution(p, v) { return v === p; }\n// usage: if (!isSelfResolution(p, value)) resolve(value);","tryCatchPattern":"try {\n  await p;\n} catch (e) {\n  if (e instanceof TypeError && /resolved itself|Chaining cycle/.test(e.message)) {\n    // break the cycle: resolve with a derived value instead\n  } else throw e;\n}","preventionTips":["Never pass the promise variable itself to resolve().","Name the promise and the resolved value distinctly to avoid shadowing.","Review executor code for closures capturing the outer promise.","Watch for thenables that contain their own container promise (circular structures)."],"tags":["javascript","polyfill","promise","typeerror"],"backgroundTag":"promise-resolved-with-itself","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}