Registry / devops / inflight-lru

inflight-lru

JSON →
library1.0.0jsnpmunverified

Drop-in replacement for the deprecated inflight package, using lru-cache under the hood. Version 1.0.0 provides the same API as the original inflight (add, remove, has, list, clear) but backed by an LRU cache to prevent memory leaks. Useful as a resolution override in package.json for Yarn/npm to replace the deprecated inflight dependency used by many npm packages (e.g., glob, rimraf). Published manually; no release cadence established.

npm install inflight-lru
INSTALL
IMPORT
SIG · INFLIGHT-LRU
I
inflight-lru
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

inflight
const inflight = require('inflight-lru')
import inflight from 'inflight-lru' // default export is CommonJS, not ESM
This package is CommonJS-only (no ESM module). Use require(). The exported function has the same signature as the original inflight.
inflight
import inflight from 'inflight-lru' // May work with bundlers that handle CJS, but Node.js native ESM will fail
import { inflight } from 'inflight-lru' // Wrong: it's a default export, not named
If using TypeScript with esModuleInterop, default import may compile to require. For native ESM, use createRequire or stick to CommonJS.
inflight
const inflight = require('inflight').default // Not necessary for this package
const { default: inflight } = require('inflight-lru') // Unnecessary indirection
The package exports a single function directly, not via default property. Keep it simple.

Demonstrates creating an inflight function with the same API as original, using lru-cache for deduplication.

const inflight = require('inflight-lru'); // Simulate an async operation with a unique key const key = 'myOperation'; // The first call creates the promise, subsequent calls with same key return the same promise const result1 = inflight(key, () => { return new Promise((resolve) => { setTimeout(() => resolve('done'), 100); }); }); const result2 = inflight(key, () => { return Promise.resolve('different'); // ignored, returns result1's promise }); // Both resolve to 'done' const [a, b] = await Promise.all([result1, result2]); console.log(a, b); // 'done done' // Cache can be cleared inflight.clear(); // empties the LRU cache
Debug
Known issues
breakingThe original inflight had no size limit, potentially causing memory issues. inflight-lru uses an LRU cache which evicts old entries. If your code relies on entries staying indefinitely, this will break after the cache limit is reached (default max: 500).
fix
Set a larger max option when creating the inflight instance (not yet configurable in v1.0.0). Or avoid relying on long-lived inflight keys.
affects: >=1.0.0
deprecatedThis package replaces the deprecated inflight package. The original inflight is deprecated and should not be used directly.
fix
Use inflight-lru as a resolution override to replace inflight in your dependency tree.
affects: >=1.0.0
gotchaThe package is CommonJS-only. If your project uses ESM (e.g., "type": "module" in package.json), require will fail. You must use createRequire or dynamic import.
fix
Use createRequire: import { createRequire } from 'module'; const require = createRequire(import.meta.url); const inflight = require('inflight-lru');
affects: >=1.0.0
gotchaTypeScript users may need to install @types/inflight (the original) for type definitions, or declare module 'inflight-lru' manually.
fix
npm install -D @types/inflight and add "inflight-lru": ["inflight"] in tsconfig paths, or create a .d.ts file: declare module 'inflight-lru';
affects: >=1.0.0
gotchaThe package is published manually; there may be long gaps between releases. Check the GitHub repo for the latest code.
fix
If you need newer features, consider forking or using the original lru-cache directly with your own inflight implementation.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'inflight-lru'
Package is not installed or version is incorrect in node_modules.
fix
Run npm install inflight-lru@^1.0.0 or add to package.json resolutions.
TypeError: inflight is not a function
Using wrong import syntax (e.g., named import instead of default).
fix
Use const inflight = require('inflight-lru'); (default import).
ReferenceError: require is not defined in ES module scope
The package is CommonJS, but your project uses ES modules (type: module).
fix
Use createRequire from 'module' as described above.
Cannot use import statement outside a module
Using ESM import syntax in a CommonJS file without transpilation.
fix
Change to require() or add "type": "module" in package.json and ensure Node version supports ESM.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
lru-cacherequiredCore underlying LRU cache implementation used to replace inflight's internal map
Agent activity
4 hits · last 30 days
node
4
Resources