{"id":44493,"library":"cache-path","title":"cache-path","description":"A drop-in alternative to find-cache-dir that returns a cache directory path in any environment, even outside a module/package folder. Version 4.0.11, maintained in a monorepo with TypeScript types included. Key differentiators: (1) never fails when not inside a module/package, (2) customizable priority order for cache path discovery, (3) async API available. Supports both ESM and CommonJS, with normalized name generation for scoped packages.","status":"active","version":"4.0.11","language":"javascript","source_language":"en","source_url":"https://github.com/bluelovers/ws-yarn-workspaces","tags":["javascript","cache","caching","dir","directory","find","async","sync","folder","typescript"],"install":[{"cmd":"npm install cache-path","lang":"bash","label":"npm"},{"cmd":"yarn add cache-path","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-path","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a named export, not a default export.","wrong":"import getCachePath from 'cache-path'","symbol":"getCachePath","correct":"import { getCachePath } from 'cache-path'"},{"note":"CJS require works but ESM import is preferred.","wrong":"const normalizeName = require('cache-path').normalizeName","symbol":"normalizeName","correct":"import { normalizeName } from 'cache-path'"},{"note":"Async version of getCachePath; available since v4.","wrong":null,"symbol":"getCachePathAsync","correct":"import { getCachePathAsync } from 'cache-path'"}],"quickstart":{"code":"import { normalizeName, getCachePath } from 'cache-path';\n\nconsole.log(normalizeName('@node-novel/sort'));\n// => _node_novel_sort\nconsole.log(normalizeName('@node-novel/sort', true));\n// => 7bc015f2\n\nconsole.log(getCachePath());\n// => e.g., /home/user/.cache/npm/.cache\nconsole.log(getCachePath('@node-novel/sort'));\n// => /home/user/.cache/npm/.cache/_node_novel_sort\n\n// async version\nimport { getCachePathAsync } from 'cache-path';\nconst path = await getCachePathAsync('my-app');\nconsole.log(path);","lang":"typescript","description":"Demonstrates basic usage of normalizeName and getCachePath sync/async, including scoped package normalization."},"warnings":[{"fix":"Change import { getCachePath } from 'cache-path' instead of import cachePath from 'cache-path'.","message":"From version 2 to 3, the default export was removed; all exports are now named.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Use getCachePathAsync if async I/O acceptable.","message":"The sync function getCachePath is still available but consider using getCachePathAsync for non-blocking behavior.","severity":"deprecated","affected_versions":"*"},{"fix":"Check if the returned path is writable before using.","message":"The package uses a custom priority order for cache directories; if no cache directory found, it may return a fallback like /tmp. This differs from find-cache-dir which throws.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'1':40 '2':48 '3':56 '4.0.11':29 'altern':8 'api':58 'async':57,78 'avail':59 'cach':2,12,17,53,73,74 'cache-path':1 'commonj':64 'customiz':49 'differenti':39 'dir':13,75 'directori':18,76 'discoveri':55 'drop':6 'drop-in':5 'environ':22 'esm':62 'even':23 'fail':42 'find':11,77 'find-cache-dir':10 'folder':27,80 'generat':68 'includ':37 'insid':45 'javascript':72 'key':38 'maintain':30 'module/package':26,47 'monorepo':33 'name':67 'never':41 'normal':66 'order':51 'outsid':24 'packag':71 'path':3,19,54 'prioriti':50 'return':15 'scope':70 'support':60 'sync':79 'type':36 'typescript':35,81 'version':28","created_at":"2026-06-07T12:50:24.271757+00:00","updated_at":"2026-06-07T12:50:24.271757+00:00","problems":[{"fix":"Run 'npm install cache-path' and ensure import uses named export.","cause":"Package not installed or import path incorrect.","error":"Cannot find module 'cache-path'"},{"fix":"Change to import { getCachePath } from 'cache-path'.","cause":"Using default import instead of named import.","error":"cache-path_1.getCachePath is not a function"},{"fix":"Use normalizeName (lowercase n).","cause":"Typo in function name (capital N).","error":"NormalizeName is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/cache-path#readme","github":"https://github.com/bluelovers/ws-yarn-workspaces","docs":null,"changelog":null,"pypi":null,"npm":"cache-path","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}