{"id":15339,"library":"is-promise","title":"is-promise","description":"is-promise is a minimalist utility that determines if an object adheres to the Promises/A+ specification by duck-typing, specifically checking for the presence and function type of a `then` method. The package is currently at version 4.0.0, which primarily introduced a breaking change for TypeScript users regarding `PromiseLike` inference. While it doesn't follow a strict, rapid release cadence, major versions address significant compatibility updates, particularly concerning module resolution in Node.js environments and TypeScript definitions. Its key differentiator is its small footprint and focused API, providing a reliable and agnostic way to identify promise-like objects, useful in contexts where various promise implementations or thenables might be encountered, without relying on a global `Promise` constructor.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/then/is-promise","tags":["javascript"],"install":[{"cmd":"npm install is-promise","lang":"bash","label":"npm"},{"cmd":"yarn add is-promise","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-promise","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v3.0.0, is-promise uses default exports in ES Modules environments. Attempting to use named imports will result in `isPromise is not a function`.","wrong":"import { isPromise } from 'is-promise';","symbol":"isPromise","correct":"import isPromise from 'is-promise';"},{"note":"This is the correct CommonJS `require` pattern, supported across all recent versions.","symbol":"isPromise","correct":"const isPromise = require('is-promise');"}],"quickstart":{"code":"import isPromise from 'is-promise';\n\nasync function processValue(value: unknown): Promise<string> {\n  if (isPromise(value)) {\n    console.log('Value is a promise, awaiting...');\n    const result = await value;\n    return `Resolved from promise: ${result}`;\n  } else if (typeof value === 'string') {\n    console.log('Value is a string.');\n    return `Direct string: ${value}`;\n  } else if (typeof value === 'object' && value !== null && 'then' in value && typeof (value as any).then === 'function') {\n    console.log('Value is promise-like (has a then method), awaiting...');\n    const result = await (value as PromiseLike<any>);\n    return `Resolved from promise-like: ${result}`;\n  } else {\n    console.log('Value is neither a promise nor a string.');\n    return 'Unknown value type.';\n  }\n}\n\n(async () => {\n  console.log(await processValue(Promise.resolve('Hello from a real promise')));\n  console.log(await processValue({ then: (resolve: (arg0: string) => void) => setTimeout(() => resolve('Hello from a custom thenable'), 100) }));\n  console.log(await processValue('Hello from a string'));\n  console.log(await processValue(null));\n  console.log(await processValue({ then: true })); // 'then' is not a function, so not a promise.\n})();","lang":"typescript","description":"Demonstrates how to use `isPromise` to check various values, including actual promises, custom thenables, and non-promise types, and correctly handle their resolution."},"warnings":[{"fix":"Review TypeScript code that uses `isPromise` to ensure correct type handling, especially in function return types or conditional branches, adjusting types from `Promise<T>` to `PromiseLike<T>` where appropriate.","message":"For TypeScript users, `is-promise` v4.0.0 changed its internal type inference from `Promise` to `PromiseLike`. This change correctly reflects that the library checks for any object with a `.then()` method, not strictly instances of the global `Promise` constructor. Type inference in user code might behave differently.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Avoid importing or requiring any paths other than the main package entry point (`is-promise`). If you were relying on internal package files, find alternative ways to access that information (e.g., read the main `package.json` of your *own* project).","message":"Version 3.0.0 introduced restricted \"exports\" in `package.json` for Node 14+ environments. This means that only the public API (the main `isPromise` function) is accessible. Directly requiring or importing internal files, such as the `package.json` file of the package itself, is no longer supported and will result in module not found errors.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update all ES Module imports to use the default import syntax: `import isPromise from 'is-promise';`.","message":"Since v3.0.0, `is-promise` uses default exports in ES Modules environments. If you were previously using named imports (e.g., `import { isPromise } from 'is-promise'`) with earlier ESM-enabled versions, this pattern will no longer work and will cause runtime errors.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Do not use `is-promise` versions 2.2.0 or 2.2.1. Upgrade to 2.2.2 or any subsequent stable version (e.g., 3.x or 4.x).","message":"Versions 2.2.0 and 2.2.1 of `is-promise` were officially marked as broken due to issues with their initial attempts at adding ES Module support, which led to incorrect module resolution and other problems. These versions should be avoided.","severity":"breaking","affected_versions":"2.2.0 - 2.2.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change the import statement to use the default export: `import isPromise from 'is-promise';` (applicable for v3.0.0 and above).","cause":"Attempting to use `isPromise` as a named import (e.g., `import { isPromise } from 'is-promise';`) in an ES Module environment.","error":"TypeError: isPromise is not a function"},{"fix":"Access to internal package files is no longer supported. If you need information from `is-promise`'s `package.json`, consider hardcoding it or finding another way to obtain it that doesn't involve directly accessing its internal file structure.","cause":"Trying to `require` or `import` a subpath (like the package's `package.json` file) directly from `is-promise` after v3.0.0, which restricted exports.","error":"Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not exported from package 'is-promise'"}],"ecosystem":"npm"}