tsconfck is a robust utility designed to find and parse `tsconfig.json` or `jsconfig.json` files programmatically, abstracting away the complexities of TypeScript's native parsing mechanisms. It enables developers to work with TypeScript configuration files without requiring a direct dependency on the `typescript` package itself, offering a lightweight alternative. The current stable version is 3.1.6, with a release cadence that appears to be frequent patch releases addressing bug fixes and minor improvements, as seen in the recent changelog for 3.1.x. Key differentiators include its ability to resolve `extends` and `references` properties, optional caching for performance, a minimal bundle size (4.8KB gzip), and being completely asynchronous. It also offers `parseNative` for when the `typescript` peer dependency *is* present and desired for official API usage. It's notably used by popular tools like Vite and Astro for their configuration needs.
npm install tsconfckVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to find and parse a tsconfig.json file using the `parse` function from `tsconfck` based on a source file path. It creates a temporary project structure, parses its config, and then cleans up.
Migrate your project to use ES modules, or dynamically import `tsconfck` using `await import('tsconfck')` if you must remain in a CommonJS context.Ensure `typescript` is installed as a peer dependency with a compatible version (e.g., `npm install typescript@^5.0.0` or `pnpm add typescript@^5.0.0`). For parsing without `typescript`, use the `parse` function instead.
Implement explicit cache invalidation logic, such as calling `cache.clear()` when configuration files are known to have changed (e.g., on file watch events, before a build starts).
Upgrade to `tsconfck@3.1.4` or newer to ensure correct glob matching behavior. If upgrading is not possible, explicitly add `/**/*` to such path patterns in your `tsconfig.json`.
Upgrade to `tsconfck@3.1.5` or newer to get fixes for `${configDir}` resolution in referenced files. For `extends: '..'` edge cases, version 3.1.6 contains specific fixes.Change your import statement to `import { parse } from 'tsconfck';` and ensure your environment supports ES modules (e.g., `type: 'module'` in package.json or running with a modern Node.js version).Install `typescript` as a peer dependency: `npm install typescript@^5.0.0` or use the `parse` function instead, which does not require `typescript`.
Verify your `tsconfig.json` for syntax errors. Use a JSON linter or validator to ensure it's valid JSON. If the error persists, it might indicate an issue with how `tsconfck` handles specific non-standard JSON constructs in older versions.