Registry / devops / find-cache-directory

find-cache-directory

JSON →
library6.0.0jsnpmunverified

Finds the common standard cache directory (e.g., ./node_modules/.cache) across projects. Version 6.0.0 is the latest stable release, with a yearly release cadence. This package is part of a shared spec adopted by AVA, nyc, and others. Unlike generic cache path utilities (like env-paths), it relies on a package.json discovery algorithm and respects the CACHE_DIR environment variable. Ship TypeScript type definitions and requires Node.js >= 20.

npm install find-cache-directory
INSTALL
IMPORT
SIG · FIND-CACHE-DIRECTO
F
find-cache-directory
devopsjavascriptv6.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.

findCacheDirectory
import findCacheDirectory from 'find-cache-directory'
const findCacheDirectory = require('find-cache-directory')
ESM-only since v5; CommonJS require will fail with Module not found. Use dynamic import() if needed.
default export
import findCacheDirectory from 'find-cache-directory'
import { findCacheDirectory } from 'find-cache-directory'
The module uses a default export, not named. Named import will result in undefined.
type import
import type { Options } from 'find-cache-directory'
TypeScript types are exported; use import type for type-only imports.

Finds and optionally creates the cache directory for a project named 'my-app'.

import findCacheDirectory from 'find-cache-directory'; const cacheDir = findCacheDirectory({ name: 'my-app', create: true // creates directory if not exists }); if (cacheDir) { console.log(`Cache directory: ${cacheDir}`); } else { console.log('Could not determine cache directory'); }
Debug
Known issues
breakingv5 dropped CommonJS support; require() will fail.
fix
Use import or dynamic import('find-cache-directory').
affects: >=5.0.0
breakingv6 requires Node.js >= 20.
fix
Upgrade Node.js or use v4.x (last CJS version).
affects: >=6.0.0
deprecatedOptions `thunk` and `create` were removed in v4; use `create: true` directly.
fix
Avoid thunk; use `create: true` on options object.
affects: >=4.0.0 <5.0.0
gotchaIf `CACHE_DIR` env var is set to 'true', 'false', '1', or '0', it is ignored and falls back to normal resolution.
fix
Set CACHE_DIR to an absolute path string to override.
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'find-cache-directory'
CommonJS require() used with ESM-only package
fix
Use `import findCacheDirectory from 'find-cache-directory'` or use dynamic `import('find-cache-directory')`
findCacheDirectory is undefined
Tried to use named import instead of default import
fix
Use `import findCacheDirectory from 'find-cache-directory'` (no curly braces)
TypeError: findCacheDirectory is not a function
Incorrect import pattern (e.g., `const findCacheDirectory = require('find-cache-directory')` with ES module)
fix
Use ESM import syntax
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
Bingbot
1
Resources
find-cache-directory — npm install find-cache-directory · libregistry