{"id":17773,"library":"kyt-utils","title":"Kyt Utilities","description":"Kyt Utilities (`kyt-utils`) is an internal utility library developed by The New York Times, forming a core component of the `kyt` ecosystem, which is a React starter kit and framework. This package provides specialized helper functions designed for internal use within `kyt`-based applications and the `kyt` build system. Its functionalities include resolving project configurations, managing webpack setup, and handling environment variables and port assignments. The current stable version is 1.3.34. While it doesn't follow an independent public release cadence, it is actively maintained as part of the larger `kyt` mono-repository. Its primary purpose is to support the `kyt` framework, making it distinct from general-purpose utility libraries.","status":"active","version":"1.3.34","language":"javascript","source_language":"en","source_url":"https://github.com/nytimes/kyt","tags":["javascript"],"install":[{"cmd":"npm install kyt-utils","lang":"bash","label":"npm"},{"cmd":"yarn add kyt-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add kyt-utils","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides various general-purpose utility functions used internally across the utility set.","package":"lodash","optional":false}],"imports":[{"note":"Many `kyt-utils` exports are from specific subpaths (e.g., `/utils`, `/config`, `/webpack`), not directly from the root package. While `kyt`'s build system might use CommonJS, modern userland consumption typically uses ESM named imports.","wrong":"import { resolveCwd } from 'kyt-utils'; // Incorrect subpath\nconst { resolveCwd } = require('kyt-utils/utils'); // CommonJS in an ESM-only context","symbol":"resolveCwd","correct":"import { resolveCwd } from 'kyt-utils/utils';"},{"note":"This function is primarily used within the `kyt` build process to generate webpack configurations. It is a named export from the `/webpack` subpath and expects a configuration object as an argument.","wrong":"import getWebpackConfig from 'kyt-utils/webpack'; // Not a default export\nconst getWebpackConfig = require('kyt-utils/webpack'); // CommonJS import of named export","symbol":"getWebpackConfig","correct":"import { getWebpackConfig } from 'kyt-utils/webpack';"},{"note":"Used for resolving an available network port, commonly for development servers. This utility is exported as a named export from the `/config` subpath and takes an options object (e.g., `{ port, host }`).","wrong":"import * as config from 'kyt-utils/config'; // While technically correct, not idiomatic for single symbol\nimport getPort from 'kyt-utils/config'; // Not a default export","symbol":"getPort","correct":"import { getPort } from 'kyt-utils/config';"}],"quickstart":{"code":"import { resolveCwd, resolveAppConfig } from 'kyt-utils/utils';\nimport { getPort } from 'kyt-utils/config';\n\n// Resolve the current working directory of the project.\nconst projectRoot = resolveCwd();\nconsole.log(`Project root resolved to: ${projectRoot}`);\n\n// Resolve the application-specific configuration. This typically involves\n// loading and merging various config files based on environment.\nconst appConfig = resolveAppConfig();\nconsole.log('Resolved Application Config:', appConfig);\n\n// Asynchronously find an available port, often for a development server.\n// getPort typically returns a Promise that resolves with an available port.\nasync function findAndLogPort() {\n  try {\n    const suggestedPort = parseInt(process.env.PORT ?? '3000', 10);\n    const availablePort = await getPort({ port: suggestedPort, host: 'localhost' });\n    console.log(`An available port found at: ${availablePort}`);\n  } catch (error) {\n    console.error('Failed to find an available port:', error instanceof Error ? error.message : String(error));\n  }\n}\n\nfindAndLogPort();\n","lang":"typescript","description":"Demonstrates how to import and utilize core `kyt-utils` functions for tasks such as resolving the project root, loading application configurations, and dynamically finding an available network port for development."},"warnings":[{"fix":"Prefer using `kyt`'s documented APIs where possible. If direct `kyt-utils` imports are necessary, pin exact versions to avoid unexpected breaking changes with minor updates and regularly review the `kyt` monorepo's changelog.","message":"Kyt Utilities (`kyt-utils`) is primarily an internal package of the `kyt` framework. Its public API is not explicitly documented or guaranteed to be stable across `kyt` major versions. Direct consumption should be approached with caution as functions and their signatures may change without typical semver adherence for external consumers.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review the `kyt` monorepo's changelogs around the 1.0.0 release for `kyt-utils` for specific migration steps. Update import paths and function calls to reflect the new package structure and ensure compatibility.","message":"Prior to version 1.0.0, the utilities might have been exposed differently or were part of the main `kyt` package. The transition to a dedicated `kyt-utils` package (around 1.0.0) could have introduced breaking changes for existing code that relied on previous internal structures.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Always check the specific subpath for the utility you intend to import. Refer to the `kyt-utils` source code in the `kyt` GitHub repository for the correct export paths, or inspect the package's `package.json` and build outputs.","message":"Many exports from `kyt-utils` are from specific subpaths (e.g., `kyt-utils/utils`, `kyt-utils/webpack`, `kyt-utils/config`). Incorrect import paths will result in module not found errors or undefined imports, as the root `kyt-utils` package typically doesn't re-export all its internal modules directly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be mindful of where `kyt-utils` is imported. Ensure that utilities relying on `lodash` are only consumed in Node.js environments (e.g., server-side rendering, build scripts) or that your build setup effectively tree-shakes unused `lodash` parts if used in browser bundles. Consider using smaller, purpose-built alternatives if not strictly within a `kyt` server-side context.","message":"The package depends on `lodash`. While convenient, this adds `lodash`'s full bundle size to any client-side bundles if these utilities are inadvertently bundled for the browser. This can significantly impact client-side performance and bundle size.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change the import path to a specific subpath where the utility resides, for example: `import { someFunction } from 'kyt-utils/utils';` or `import { anotherFunction } from 'kyt-utils/config';`","cause":"Attempting to import directly from 'kyt-utils' instead of a specific subpath that exports the desired utility.","error":"Module not found: Error: Can't resolve 'kyt-utils'"},{"fix":"Verify that you are using named imports (`import { someUtilityFunction } from '...'`) and that the import path precisely matches where the function is exported (e.g., `/utils`, `/webpack`, `/config`). Consult the `kyt-utils` source code for the exact export definitions.","cause":"This usually indicates an incorrect import. You might be attempting to import a named export as a default, or importing from the wrong subpath where the function is not actually exported.","error":"TypeError: someUtilityFunction is not a function"},{"fix":"Ensure that utilities designed for server-side or build-time execution are only consumed in Node.js environments. If you need similar functionality in the browser, consider implementing browser-compatible alternatives or relying on `kyt`'s client-side runtime for such features.","cause":"Many `kyt-utils` functions, especially those related to configuration and environment, rely on Node.js-specific global objects and APIs (like `process`). This error occurs when such code is executed in a browser environment.","error":"ReferenceError: process is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}