{"record":{"id":"d54ecbba4a47a56d","repo":"petkaantonov/bluebird","slug":"the-promise-constructor-cannot-be-invoked-directly","errorCode":null,"errorMessage":"the promise constructor cannot be invoked directly\n\n    See http://goo.gl/MqrFmX\n","messagePattern":"the promise constructor cannot be invoked directly\n\n    See http://goo\\.gl/MqrFmX\n","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/promise.js","lineNumber":87,"sourceCode":"var PromiseArray =\n    require(\"./promise_array\")(Promise, INTERNAL,\n                               tryConvertToPromise, apiRejection, Proxyable);\nvar Context = require(\"./context\")(Promise);\n /*jshint unused:false*/\nvar createContext = Context.create;\n\nvar debug = require(\"./debuggability\")(Promise, Context,\n    enableAsyncHooks, disableAsyncHooks);\nvar CapturedTrace = debug.CapturedTrace;\nvar PassThroughHandlerContext =\n    require(\"./finally\")(Promise, tryConvertToPromise, NEXT_FILTER);\nvar catchFilter = require(\"./catch_filter\")(NEXT_FILTER);\nvar nodebackForPromise = require(\"./nodeback\");\nvar errorObj = util.errorObj;\nvar tryCatch = util.tryCatch;\nfunction check(self, executor) {\n    if (self == null || self.constructor !== Promise) {\n        throw new TypeError(CONSTRUCT_ERROR_INVOCATION);\n    }\n    if (typeof executor !== \"function\") {\n        throw new TypeError(FUNCTION_ERROR + util.classString(executor));\n    }\n\n}\n\nfunction Promise(executor) {\n    if (executor !== INTERNAL) {\n        check(this, executor);\n    }\n    this._bitField = NO_STATE;\n    this._fulfillmentHandler0 = undefined;\n    this._rejectionHandler0 = undefined;\n    this._promise0 = undefined;\n    this._receiver0 = undefined;\n    this._resolveFromExecutor(executor);\n    this._promiseCreated();","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/petkaantonov/bluebird/blob/c220cfe480868e2f5c5de4fe8bb3b04b97588d7f/src/promise.js#L69-L105","documentation":"Bluebird's Promise constructor requires being called with `new` on the real Promise constructor with a function executor. The internal check(self, executor) throws TypeError(CONSTRUCT_ERROR_INVOCATION) when `this` is not a Bluebird Promise instance — i.e. the constructor was called without `new`, subclassed/invoked incorrectly, or the library's internal no-constructor sentinel (INTERNAL) misuse occurred.","triggerScenarios":"Calling Promise(executor) without `new`; calling the constructor with .call/.apply on a wrong this; wrapping a subclass that doesn't properly forward to Bluebird's Promise; requiring multiple bluebird copies and cross-constructing with the wrong class.","commonSituations":"Migrating from native Promise code and dropping `new`; destructured import ({Promise}) misuse; TypeScript/Babel downleveling subclassed promises incorrectly; dual bluebird installations (one in node_modules of a dependency) causing instanceof-style mismatches.","solutions":["Always use `new`: new Promise((resolve, reject) => ...)","Ensure there is exactly one bluebird version installed (dedupe with npm ls bluebird / npm dedupe)","If subclassing, call super(executor) properly or use Promise.prototype methods instead of manual construction","Check the import: the value you call `new` on must be bluebird's Promise, not a re-export that lost construct signature","For Node >= 4, consider native Promise if subclassing semantics are causing conflicts"],"exampleFix":"// before\nconst p = Promise((resolve, reject) => resolve(1)); // missing new\n// after\nconst p = new Promise((resolve, reject) => resolve(1));","handlingStrategy":"validation","validationCode":"function safeNewPromise(executor) {\n  if (typeof executor !== 'function') throw new TypeError('executor must be a function');\n  return new Promise(executor); // note: new is required\n}","typeGuard":"function isBluebirdPromise(Ctor) {\n  try { const p = new Ctor(res => res(1)); return p instanceof Promise; }\n  catch (e) { return false; }\n}","tryCatchPattern":"let p;\ntry {\n  p = new Promise((resolve, reject) => resolve(1));\n} catch (e) {\n  if (String(e.message).includes('cannot be invoked directly')) {\n    throw new Error('Use `new Promise(...)` with bluebird\\'s Promise; check for duplicate bluebird installs');\n  }\n  throw e;\n}","preventionTips":["Always call the constructor with `new`","Ensure a single bluebird version is installed (npm ls bluebird)","Do not .call/.apply the Promise constructor with a custom this","When subclassing, call super(executor) correctly","Lint for `Promise(` without `new` (no-new rule)"],"tags":["typeerror","constructor","promise"],"backgroundTag":"promise-constructor-invocation","analyzedSha":"c220cfe480868e2f5c5de4fe8bb3b04b97588d7f","analyzedAt":"2026-09-02T02:30:20.863Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}