cosmiconfig
10.0.1 · 30 Aug 2026MIT172.2M / weekRepositoryHomepagenpmAtom feed
5.2.1 is the newest release of 5.x.
In short
1 breaking1 removed12 changed
- breaking
packagePropno longer acceptsfalse. If you don't want to look inpackage.json, write asearchPlacesarray that does not include it. - removed
Removed the
formatoption. Formats are now all handled via the file extensions specified inloaders.
Release note
The API has been completely revamped to increase clarity and enable a very wide range of new usage. Please read the readme for all the details.
While the defaults remain just as useful as before — and you can still pass no options at all — now you can also do all kinds of wild and crazy things.
The
loadersoption allows you specify custom functions to derive config objects from files. Your loader functions could parse ES2015 modules or TypeScript, JSON5, even INI or XML. Whatever suits you.The
searchPlacesoption allows you to specify exactly where cosmiconfig looks within each directory it searches.The combination of
loadersandsearchPlacesmeans that you should be able to load pretty much any kind of configuration file you want, from wherever you want it to look.
Additionally, the overloaded load() function has been split up into several clear and focused functions:
search()now searches up the directory tree, andload()loads a configuration file that you don't need to search for.The
syncoption has been replaced with separate synchronous functions:searchSync()andloadSync().clearFileCache()andclearDirectoryCache()have been renamed toclearLoadCache()andclearSearchPath()respectively.
More details:
The default JS loader uses
require, instead ofrequire-from-string. So you could userequirehooks to control the loading of JS files (e.g. pass them through esm or Babel). In most cases it is probably preferable to use a custom loader.The options
rc,js, andrcExtensionshave all been removed. You can accomplish the same and more withsearchPlaces.The default
searchPlacesincludercfiles with extensions, e.g..thingrc.json,.thingrc.yaml,.thingrc.yml. This is the equivalent of switching the default value of the oldrcExtensionsoption totrue.The option
rcStrictJsonhas been removed. To get the same effect, you can specifynoExt: cosmiconfig.loadJsonin yourloadersobject.- breaking
packagePropno longer acceptsfalse. If you don't want to look inpackage.json, write asearchPlacesarray that does not include it. By default, empty files are ignored by
search(). The new optionignoreEmptySearchPlacesallows you to load them, instead, in case you want to do something with empty files.The option
configPathhas been removed. Just pass your filepaths directory toload().- removed
Removed the
formatoption. Formats are now all handled via the file extensions specified inloaders.
(If you're wondering with happened to 5.0.0 ... it was a silly publishing mistake.)