Registry / devops / unplugin-typesugar

unplugin-typesugar

JSON →
library0.1.1jsnpmunverified

unplugin-typesugar provides essential bundler integrations for `typesugar`, a TypeScript macro expansion library. It enables compile-time macro processing across various build tools, including Vite, Webpack, esbuild, and Rollup. Leveraging the `unplugin` ecosystem, it ensures broad compatibility and simplifies integration into existing JavaScript and TypeScript projects. The current stable version is 0.1.1, marked as an initial release candidate and first stable patch, indicating active, early-stage development with frequent updates addressing stability and feature enhancements. A key differentiator is its ability to expand TypeScript macros before the code enters the bundler's optimization pipeline, ensuring that macro-transformed code is fully optimized. It requires TypeScript 5.0 or newer as a peer dependency, aligning with modern TypeScript tooling practices.

npm install unplugin-typesugar
INSTALL
IMPORT
SIG · UNPLUGIN-TYPESUGAR
U
unplugin-typesugar
devopsjavascriptv0.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

typesugar
import typesugar from "unplugin-typesugar/vite";
const typesugar = require("unplugin-typesugar/vite");
Use named import for Vite, Rollup, and esbuild. These are typically ESM-only.
typesugar
const typesugar = require("unplugin-typesugar/webpack").default;
import typesugar from "unplugin-typesugar/webpack";
Webpack configuration files often run in CommonJS contexts and require accessing the .default export.
TypesugarPluginOptions
import type { TypesugarPluginOptions } from 'unplugin-typesugar';
Import types explicitly using 'import type' for clarity and tree-shaking benefits.

Demonstrates how to integrate unplugin-typesugar into a Vite project with common configuration options, including verbose logging, file pattern matching, disk caching, and strict type-checking of expanded output.

import typesugar from "unplugin-typesugar/vite"; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ typesugar({ verbose: true, include: /src\/.*\.tsx?$/, exclude: /\.test\.ts$/, diskCache: true, // Enable disk cache for faster rebuilds strict: true // Typecheck expanded output at build end }), ], });
Debug
Known issues
gotchaunplugin-typesugar is in its early development stages (current version 0.1.1). APIs may undergo rapid changes in minor or patch releases prior to reaching a stable 1.0 version.
fix
Review release notes carefully for any breaking changes when upgrading. Consider pinning to exact patch versions for critical applications.
affects: <1.0.0
breakingThis plugin requires TypeScript version 5.0.0 or higher due to its reliance on newer TypeScript compiler APIs for macro transformation.
fix
Ensure your project's `typescript` peer dependency is satisfied by upgrading to `typescript@>=5.0.0` in your `package.json`.
affects: >=0.1.1
breakingInitial release candidates (prior to 0.1.1) experienced a build crash with a 'start < 0' error. This was resolved in version 0.1.1.
fix
Upgrade `unplugin-typesugar` to version 0.1.1 or newer to resolve this critical build issue.
affects: <0.1.1
Errors
Common errors & fixes
Plugin 'unplugin-typesugar' failed to load. Cannot find module 'unplugin-typesugar/vite' (or /webpack, /esbuild, /rollup)
The specific bundler integration path is incorrect, or the `unplugin-typesugar` package is not correctly installed.
fix
Verify that `unplugin-typesugar` is installed (`npm install unplugin-typesugar` or `pnpm add unplugin-typesugar`) and that the import path matches your bundler (e.g., `import typesugar from 'unplugin-typesugar/vite';`).
TypeError: Cannot read properties of undefined (reading 'default') in Webpack configuration
Attempting to use an ESM import statement (`import typesugar from '...'`) or incorrectly accessing the CommonJS module's export in a Webpack configuration file, which typically runs in a CommonJS environment.
fix
For Webpack, use `const typesugar = require('unplugin-typesugar/webpack').default;` to correctly import the plugin.
Property 'getDiagnostics' does not exist on type 'Program' (or similar TypeScript API errors during build)
The installed TypeScript version is incompatible with `unplugin-typesugar`, which requires TypeScript 5.0 or newer.
fix
Upgrade your project's `typescript` dependency to `typescript@>=5.0.0` to ensure compatibility with the plugin's internal TypeScript program creation.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
typescriptrequiredRequired peer dependency for TypeScript macro expansion and program creation.
Agent activity
4 hits · last 30 days
node
4
Resources
unplugin-typesugar — npm install unplugin-typesugar · libregistry