{"id":12936,"library":"bun-plugin-dtsx","title":"Bun DTSX Plugin","description":"Bun-plugin-dtsx is a specialized Bun Bundler plugin designed for rapidly generating TypeScript declaration files (DTS) directly during the build process. As of its current stable version, 0.9.13, the package maintains a consistent, albeit minor, release cadence with frequent patch and minor updates, often noting 'no significant changes' in recent versions. This indicates a focus on stability and incremental improvements within its pre-1.0 development phase. Its primary differentiator lies in its tight integration with the Bun runtime and bundler, offering an extremely fast solution for type emission compared to more generalized TypeScript compilation pipelines. It is essential for projects leveraging Bun that require `.d.ts` files for their distributed packages or internal module resolution, ensuring type safety and IDE support for consumers of the compiled output. It aims to streamline the development workflow for TypeScript projects built with Bun.","status":"active","version":"0.9.13","language":"javascript","source_language":"en","source_url":"https://github.com/stacksjs/dtsx","tags":["javascript","dts","dtsx","emit","generation","typescript","types","auto","stacks"],"install":[{"cmd":"npm install bun-plugin-dtsx","lang":"bash","label":"npm"},{"cmd":"yarn add bun-plugin-dtsx","lang":"bash","label":"yarn"},{"cmd":"pnpm add bun-plugin-dtsx","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime environment for the plugin to operate.","package":"bun","optional":false},{"reason":"Core dependency for parsing and emitting TypeScript declaration files.","package":"typescript","optional":false}],"imports":[{"note":"The primary plugin function is typically a default export. Bun heavily favors ESM imports.","wrong":"const dtsx = require('bun-plugin-dtsx');","symbol":"dtsx","correct":"import dtsx from 'bun-plugin-dtsx';"}],"quickstart":{"code":"import { build } from 'bun';\nimport dtsx from 'bun-plugin-dtsx';\n\nconst entrypoint = './src/index.ts';\nconst outputPath = './dist';\n\nconsole.log(`Starting Bun build with DTSX for ${entrypoint}...`);\n\nawait build({\n  entrypoints: [entrypoint],\n  outdir: outputPath,\n  target: 'bun', // Or 'node', 'browser' depending on your target environment\n  plugins: [\n    dtsx({\n      // Optional: configuration options for dtsx\n      // For example, to specify a custom tsconfig path:\n      // project: './tsconfig.build.json',\n      // To output types to a separate directory (relative to outdir):\n      // outDir: './types',\n    }),\n  ],\n  minify: true,\n  sourcemap: 'external',\n});\n\nconsole.log('Bun build with DTSX type generation complete!');\nconsole.log(`Check ${outputPath} for bundled code and generated .d.ts files.`);","lang":"typescript","description":"Demonstrates how to integrate `bun-plugin-dtsx` into a `Bun.build` process to generate TypeScript declaration files alongside your bundled output."},"warnings":[{"fix":"Regularly review the GitHub releases page and test your builds after updating the package.","message":"As a pre-1.0 release (version 0.9.x), `bun-plugin-dtsx` may introduce breaking changes in minor or even patch releases. While recent changes logs show 'no significant changes', API stability is not guaranteed until a 1.0 stable release.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure you are running your build process with Bun (e.g., `bun build ...` or `bun run your-build-script.ts`).","message":"This plugin is designed exclusively for the Bun runtime and bundler. It is not compatible with other JavaScript runtimes (like Node.js) or bundlers (like Webpack, Rollup, or esbuild) outside of a Bun build context.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider setting `declaration: false` and `emitDeclarationOnly: false` in your `tsconfig.json` when using `bun-plugin-dtsx`, as the plugin handles the type generation.","message":"If your `tsconfig.json` already has `declaration: true` or `emitDeclarationOnly: true`, `bun-plugin-dtsx` might conflict or duplicate efforts. It's generally recommended to let `dtsx` manage type emission and potentially disable these options in your `tsconfig.json` for Bun builds.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the package using `bun add bun-plugin-dtsx` and verify the import statement `import dtsx from 'bun-plugin-dtsx';`.","cause":"The package `bun-plugin-dtsx` is not installed or the import path is incorrect.","error":"error: Cannot find module 'bun-plugin-dtsx'"},{"fix":"Ensure you are calling the plugin function, e.g., `plugins: [dtsx({ /* options */ })]`.","cause":"The `dtsx` function was not called when passed to the `plugins` array, or its return value is not a valid BunPlugin object.","error":"error: plugins must be functions that return a BunPlugin object or a BunPlugin object directly"},{"fix":"Review and resolve the specific TypeScript errors indicated in the diagnostic messages within your source files.","cause":"The type generation process failed due to underlying TypeScript compilation errors in your source code. `bun-plugin-dtsx` relies on a valid TypeScript compilation to emit declarations.","error":"error: TypeScript diagnostics: [TSxxxx] ... (during build with bun-plugin-dtsx)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}