Registry / web-framework / astrojs-compiler-sync

astrojs-compiler-sync

JSON →
library1.1.1jsnpmunverified

A synchronous wrapper around the @astrojs/compiler, enabling synchronous processing of Astro files. Current stable version is 1.1.1. Maintained actively with regular releases. Key differentiator: unlike the official compiler which is async-only, this package provides a sync API for use in environments where async is inconvenient, such as certain build tools or scripts. Requires @astrojs/compiler >=0.27.0 as a peer dependency and Node.js ^18.18.0 || >=20.9.0. Ships TypeScript definitions.

npm install astrojs-compiler-sync
INSTALL
IMPORT
SIG · ASTROJS-COMPILER-S
A
astrojs-compiler-sync
web-frameworkjavascriptv1.1.1
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.

parse
import { parse } from 'astrojs-compiler-sync'
const { parse } = require('astrojs-compiler-sync')
Package is ESM-first; CommonJS require may work in some environments but is not recommended.
transform
import { transform } from 'astrojs-compiler-sync'
import { transform } from '@astrojs/compiler'
The official compiler exports transform as async; this package provides a synchronous version.
convertToTSX
import { convertToTSX } from 'astrojs-compiler-sync'
Synchronous version of the compiler's convertToTSX.

Shows how to synchronously parse and transform Astro code using the sync wrapper.

import { parse, transform } from 'astrojs-compiler-sync'; const code = `<html><body><h1>Hello</h1></body></html>`; // Parse const parsed = parse(code); console.log('Parsed AST:', parsed.ast); // Transform const result = transform(code, { sourcemap: true }); console.log('Transformed code:', result.code); console.log('Source map:', result.map);
Debug
Known issues
breakingDropped support for Node.js <18.18 (v1.0.0)
fix
Upgrade Node.js to ^18.18.0 or >=20.9.0.
affects: >=1.0.0
breakingRequires @astrojs/compiler >=0.27.0 (v0.3.0)
fix
Update @astrojs/compiler to >=0.27.0 (e.g., npm install @astrojs/compiler@latest).
affects: >=0.3.0
gotchaCJS entry typo fixed in v1.1.0 - incorrect typing for cjs entry
fix
Update to v1.1.0 or later.
affects: <1.1.0
gotchaCrash in browser for earlier versions (fixed in v0.3.3)
fix
Update to >=0.3.3.
affects: <0.3.3
deprecatedOlder versions use require('cjs') internally; v1.1.1 refactored to use require directly in CJS context
fix
Update to v1.1.1 to avoid potential issues with CJS bundlers.
affects: <1.1.1
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module not supported
Using CommonJS require to import an ESM package.
fix
Use dynamic import() or convert to ESM and use import statements.
Cannot find module '@astrojs/compiler'
Missing peer dependency @astrojs/compiler.
fix
Run npm install @astrojs/compiler@>=0.27.0.
parse is not a function
Incorrect import (e.g., default import instead of named export).
fix
Use import { parse } from 'astrojs-compiler-sync'.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
@astrojs/compilerrequiredpeer dependency; the actual Astro compiler that this package wraps synchronously
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
astrojs-compiler-sync — npm install astrojs-compiler-sync · libregistry