Lightning CSS (macOS x64)
lightningcss-darwin-x64 is the platform-specific native binary build of Lightning CSS for macOS x64 systems. Lightning CSS is an extremely fast, Rust-written CSS parser, transformer, minifier, and bundler. It is a core component in tools like Parcel and can also be used as a standalone library or CLI. The library currently ships with version 1.32.0. It offers advanced features such as vendor prefixing, syntax lowering to support older browsers, CSS Modules compilation, and support for modern CSS features like container queries, view transitions, and relative color syntax, often adopting the latest CSS specification drafts. Releases are frequent, reflecting ongoing development and adherence to evolving CSS standards. Its key differentiator is its performance, often outperforming JavaScript-based alternatives due to its Rust implementation.
Common errors
-
Error: Cannot find module 'lightningcss-darwin-x64'
cause The native binary for your operating system and architecture could not be found or loaded by the main `lightningcss` package.fixEnsure `npm install` (or `yarn install`, `pnpm install`) completed successfully. This error often occurs if the correct platform-specific package wasn't installed, if `node_modules` is corrupted, or if the `postinstall` script failed. Try `npm rebuild lightningcss` or delete `node_modules` and `package-lock.json` and reinstall. -
The 'browsers' option is required for autoprefixing.
cause The `transform` or `bundle` function was called with options that require browser targets (e.g., `minify: true`, `sourceMap: true`, or specific feature flags for transpilation) but no `targets` object was provided.fixProvide a `targets` object derived from a `browserslist` query using `browserslistToTargets`. Example: `targets: browserslistToTargets(browserslist('>= 0.25%'))`. -
SyntaxError: <css input>: Unexpected token '<some_css_token>'
cause The input CSS contains a syntax error, uses an unsupported draft feature without enabling it, or contains syntax that Lightning CSS's parser cannot understand.fixCheck the CSS input for typos or invalid syntax. If using a modern CSS draft feature (e.g., nesting, custom media queries), ensure it is explicitly enabled in the `transform` or `bundle` options, for example, `drafts: { nesting: true }`.
Warnings
- breaking Version 1.30.0 introduced breaking changes related to relative color parsing and calculation. The spec now supports numbers instead of percentages, and `calc()` expressions in colors are always treated as numbers. Code relying on old relative color calculations might need updates.
- gotcha As a native module written in Rust, `lightningcss-darwin-x64` (and other platform-specific variants) can sometimes encounter installation issues related to system dependencies, Node.js version mismatches, or incorrect platform detection by npm/yarn, leading to `Module not found` errors or build failures.
- gotcha Lightning CSS actively tracks and adopts the latest CSS specifications, including draft features like CSS nesting, relative colors, and view transitions. While this provides cutting-edge support, it means that changes in these specs can lead to subtle or breaking changes in how your CSS is processed.
- gotcha In Node.js environments, particularly when using worker threads, earlier versions of Lightning CSS experienced crashes on process exit on Linux. While a fix was released in v1.30.1, it highlights potential stability issues when integrating native modules into complex, multi-threaded Node.js applications.
- gotcha Starting with v1.32.0, custom resolvers can explicitly mark `@import` rules as external by returning `{ external: string }`. This will leave the `@import` in the output CSS instead of bundling it, which changes default bundling behavior for affected imports if custom resolvers are in use.
- gotcha While Lightning CSS can replace many PostCSS plugins (like Autoprefixer and `postcss-preset-env`), it may not fully replace all custom PostCSS setups. Integrating both `lightningcss-loader` and `postcss-loader` requires careful configuration, as some PostCSS features might be overridden or become incompatible.
Install
-
npm install lightningcss-darwin-x64 -
yarn add lightningcss-darwin-x64 -
pnpm add lightningcss-darwin-x64
Imports
- transform
const { transform } = require('lightningcss');import { transform } from 'lightningcss'; - bundle
const { bundle } = require('lightningcss');import { bundle } from 'lightningcss'; - browserslistToTargets
import browserslistToTargets from 'lightningcss/browserslistToTargets';
import { browserslistToTargets } from 'lightningcss'; - TransformOptions
import type { TransformOptions } from 'lightningcss';
Quickstart
import { transform, browserslistToTargets } from 'lightningcss';
import browserslist from 'browserslist';
import { Buffer } from 'node:buffer';
const cssInput = `
:root {
--color: oklch(50% 0.1 200);
}
@media (min-width: 768px) {
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}
}
.text-red {
color: var(--color);
text-shadow: 1px 1px red;
}
.flex-center {
display: flex;
justify-content: center;
align-items: center;
}
`;
// Determine browser targets from a browserslist query
const targets = browserslistToTargets(browserslist('last 2 Chrome versions, Firefox ESR, Edge >= 90'));
try {
const { code, map } = transform({
filename: 'input.css',
code: Buffer.from(cssInput),
minify: true,
targets, // Transpile modern CSS features for these browsers
sourceMap: true,
drafts: {
nesting: true, // Enable CSS nesting support
customMedia: true // Enable custom media queries
}
});
console.log('Transformed and minified CSS:\n', Buffer.from(code).toString());
console.log('\nSource Map:\n', Buffer.from(map).toString());
} catch (error) {
console.error('Error transforming CSS:', error);
}