cosmiconfig-typescript-loader provides a robust TypeScript loader for `cosmiconfig`, enabling applications to load configuration files written in TypeScript (e.g., `.ts` files). It is currently at version 6.3.0, with minor and patch releases occurring as needed for dependency updates and maintenance. This package serves as a maintained successor to the abandoned `@endemolshinegroup/cosmiconfig-typescript-loader`, addressing several critical issues found in the original, such as compatibility with `cosmiconfig`'s synchronous API and providing proper TypeScript support during compilation. It leverages `jiti` for on-the-fly TypeScript compilation, supporting both CommonJS and ESM environments, making it a flexible choice for modern Node.js applications that rely on TypeScript for configuration.
npm install cosmiconfig-typescript-loaderVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to integrate `cosmiconfig-typescript-loader` into a `cosmiconfig` explorer to asynchronously load a TypeScript configuration file, defining its structure with an interface.
Update calls to `explorer.load()` to `await explorer.load()` and ensure the surrounding function is `async`.
Migrate to the asynchronous `TypeScriptLoader` and adjust your code to use `await` with `explorer.load()`.
Upgrade your Node.js runtime environment to v18 or newer.
Ensure `cosmiconfig` is at least version 8. Review your `tsconfig.json` for any `ts-node`-specific configurations that might conflict with `jiti`'s behavior.
Uninstall `@endemolshinegroup/cosmiconfig-typescript-loader` and install `cosmiconfig-typescript-loader`.
Ensure you call the loader, e.g., `loaders: { ".ts": TypeScriptLoader() }` instead of `loaders: { ".ts": TypeScriptLoader }`.Ensure your `cosmiconfig` dependency is `^9.0.0` or higher, as required by `cosmiconfig-typescript-loader` v6.
Use `import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';` for ESM environments. If in a CJS context, you might need to enable `jiti`'s CJS fallback or ensure your project's module resolution is correctly configured.Manually install `jiti` as a dependency: `npm install jiti` or `yarn add jiti`.