Registry / devops / esbuild-plugin-postcss

esbuild-plugin-postcss

JSON →
library0.3.0jsnpmunverified

An esbuild plugin for importing CSS/less/scss modules with TypeScript support. Version 0.3.0 is the latest stable release; the package has had infrequent updates. It enables CSS module extraction and automatic .d.ts declaration generation for less files. Differentiators include minimal configuration, built-in declaration file generation, and esbuild-native integration. Compared to alternatives like esbuild-sass-plugin, this plugin focuses on PostCSS ecosystem compatibility and TypeScript module resolution.

npm install esbuild-plugin-postcss
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-POS
E
esbuild-plugin-postcss
devopsjavascriptv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
import PluginPostCSS from 'esbuild-plugin-postcss'
const PluginPostCSS = require('esbuild-plugin-postcss')
Package is ESM-only; CommonJS require will fail in Node ESM context. Use dynamic import or set type:module.
PluginPostCSS
import PluginPostCSS from 'esbuild-plugin-postcss'
import { PluginPostCSS } from 'esbuild-plugin-postcss'
Only default export exists; false named import causes undefined.
PostCSSPluginOptions
import type { PostCSSPluginOptions } from 'esbuild-plugin-postcss'
import { PostCSSPluginOptions } from 'esbuild-plugin-postcss'
TypeScript type import only available since v0.2.0.

Shows esbuild build with PluginPostCSS, including autoprefixer and nested postcss plugins, and declaration generation.

import esbuild from 'esbuild'; import PluginPostCSS from 'esbuild-plugin-postcss'; await esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, outdir: 'dist', plugins: [ PluginPostCSS({ declaration: true, // generate .d.ts for CSS modules plugins: [ require('autoprefixer'), require('postcss-nested'), ], }), ], loader: { '.tsx': 'tsx', '.ts': 'ts', }, });
Debug
Known issues
breakingv0.2.0 changed export from named 'PluginPostCSS' to default export only.
fix
Change import to default import: import PluginPostCSS from 'esbuild-plugin-postcss'
affects: >=0.2.0
deprecatedThe 'declaration' option for .d.ts generation works only with Less files; other preprocessors not supported and may be deprecated in future.
fix
Use 'declaration: true' only for Less; for others, manually declare module types.
affects: >=0.1.1
gotchaESM-only package; require() in CommonJS module will throw ERR_REQUIRE_ESM.
fix
Use dynamic import() or set 'type': 'module' in package.json.
affects: >=0.2.0
gotchaWhen using TypeScript, you must add a global module declaration for CSS/less files (e.g., '*.less' => Record<string, string>) to avoid type errors.
fix
Add a .d.ts file with declare module '*.less' { const content: Record<string, string>; export default content; }
affects: all
Errors
Common errors & fixes
Error: Can't find PostCSS plugin
PostCSS plugins not installed or missing in config
fix
npm install autoprefixer postcss-nested --save-dev and add to plugins array
TypeError: PluginPostCSS is not a function
Incorrect import style: trying named import instead of default
fix
Use import PluginPostCSS from 'esbuild-plugin-postcss' (default import)
Error: require() of ES Module not supported
Using CommonJS require() to load ESM-only package
fix
Switch to dynamic import() or use ESM for your project
Cannot find module 'esbuild-plugin-postcss'
Package not installed or incorrect import path
fix
npm install esbuild-plugin-postcss --save-dev and verify node_modules
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
postcssrequiredCore peer dependency for PostCSS transformations
lessoptionalRequired only if using Less files with declaration generation
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
esbuild-plugin-postcss — npm install esbuild-plugin-postcss · libregistry