css-parse is a JavaScript CSS parser originally designed for Node.js, primarily serving as a thin wrapper that exposes the `parse` method from the `css` (reworkcss/css) package. Published over a decade ago (June 2014) at its 2.0.0 version, it has not seen further updates. The underlying `reworkcss/css` library, while slightly more recent (last updated July 2020), is also largely part of an inactive ecosystem of CSS preprocessing tools (`reworkcss`). This package does not support modern CSS syntax out-of-the-box and is exclusively CommonJS. For contemporary CSS parsing, developers typically use actively maintained libraries like PostCSS, which offer broader features, plugin ecosystems, and support for the latest CSS specifications and module systems.
npm install css-parseVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a CSS string into an Abstract Syntax Tree (AST) using the `parse` method.
Consider migrating to an actively maintained CSS parser like PostCSS or a CSS-in-JS solution for robust and up-to-date CSS processing.
Use `require()` for importing. If you must use it in an ESM project, consider dynamic `import()` or a CJS wrapper, but re-evaluate if a modern ESM-compatible parser is a better fit.
When parsing potentially invalid CSS, pass `{ silent: true }` as an option: `const ast = parse(cssString, { silent: true }); if (ast.stylesheet.parsingErrors) { console.error(ast.stylesheet.parsingErrors); }`Ensure you are using `const parse = require('css-parse');` for CommonJS environments.Modify your import to `const parse = require('css-parse');` or configure your build system to handle CommonJS modules in an ESM context.Either correct the CSS syntax or parse with the `{ silent: true }` option to collect errors in `ast.stylesheet.parsingErrors` instead of throwing.