Registry / devops / clear-npx-cache

clear-npx-cache

JSON →
library1.1.2jsnpmunverified

A CLI utility that clears the NPX cache (_npx directory) to force fresh downloads of NPX-powered tools like create-react-app. Current version 1.1.2, released once. No known release cadence. Differentiator: simpler than manually removing the _npx folder; handles both creation and deletion of the cache directory. Works on all platforms with Node.js and npm. Small, zero-dependency tool that fixes a common NPX caching issue where packages are never updated in cache.

npm install clear-npx-cache
INSTALL
IMPORT
SIG · CLEAR-NPX-CACHE
C
clear-npx-cache
devopsjavascriptv1.1.2
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.

clearNpxCache
import { clearNpxCache } from 'clear-npx-cache';
const clearNpxCache = require('clear-npx-cache');
Package is ESM-only; CommonJS require may throw ERR_REQUIRE_ESM.
clearNpxCache
import { clearNpxCache } from 'clear-npx-cache';
import clearNpxCache from 'clear-npx-cache';
Not a default export; default import will yield undefined.
clearNpxCache (via CLI)
npx clear-npx-cache
Main usage is via command line; programmatic API is also available.

Demonstrates programmatic usage of clearNpxCache function, which returns a promise with the result object.

import { clearNpxCache } from 'clear-npx-cache'; import { execSync } from 'child_process'; async function main() { try { const result = await clearNpxCache(); console.log('Result:', result); // result.deleted: boolean, path: string } catch (error) { console.error('Failed to clear cache:', error.message); } } main();
Debug
Known issues
gotchaThe clearNpxCache function may remove the entire _npx directory, which could affect currently running NPX commands that rely on cached packages.
fix
Ensure no NPX commands are running concurrently when clearing cache.
affects: >=1.0.0
gotchaIf the _npx directory does not exist, the function creates an empty one, which may be unexpected for users who only want to clear.
fix
Check existence of cache directory before calling function if you want to avoid creation.
affects: >=1.0.0
gotchaThe function uses process.cwd()? No, it reads npm config get cache to find the path. But if npm config is not set, it may fail.
fix
Ensure npm is installed and configured correctly.
affects: >=1.0.0
Errors
Common errors & fixes
Error: EACCES: permission denied, unlink '/path/to/_npx/cache/file'
The function does not use sudo or elevated privileges; if the cache directory is owned by root or another user, deletion fails.
fix
Run the command with sudo (e.g., sudo npx clear-npx-cache) or adjust permissions.
TypeError: clearNpxCache is not a function
Using default import instead of named import.
fix
Use import { clearNpxCache } from 'clear-npx-cache';
ERR_REQUIRE_ESM
Using require() in CommonJS context on an ESM-only package.
fix
Switch to dynamic import: const { clearNpxCache } = await import('clear-npx-cache');
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
clear-npx-cache — npm install clear-npx-cache · libregistry