{"id":24928,"library":"astrojs-compiler-sync","title":"astrojs-compiler-sync","description":"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.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/ota-meshi/astrojs-compiler-sync","tags":["javascript","astro","astrojs","parser","typescript"],"install":[{"cmd":"npm install astrojs-compiler-sync","lang":"bash","label":"npm"},{"cmd":"yarn add astrojs-compiler-sync","lang":"bash","label":"yarn"},{"cmd":"pnpm add astrojs-compiler-sync","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; the actual Astro compiler that this package wraps synchronously","package":"@astrojs/compiler","optional":false}],"imports":[{"note":"Package is ESM-first; CommonJS require may work in some environments but is not recommended.","wrong":"const { parse } = require('astrojs-compiler-sync')","symbol":"parse","correct":"import { parse } from 'astrojs-compiler-sync'"},{"note":"The official compiler exports transform as async; this package provides a synchronous version.","wrong":"import { transform } from '@astrojs/compiler'","symbol":"transform","correct":"import { transform } from 'astrojs-compiler-sync'"},{"note":"Synchronous version of the compiler's convertToTSX.","wrong":"","symbol":"convertToTSX","correct":"import { convertToTSX } from 'astrojs-compiler-sync'"}],"quickstart":{"code":"import { parse, transform } from 'astrojs-compiler-sync';\n\nconst code = `<html><body><h1>Hello</h1></body></html>`;\n\n// Parse\nconst parsed = parse(code);\nconsole.log('Parsed AST:', parsed.ast);\n\n// Transform\nconst result = transform(code, { sourcemap: true });\nconsole.log('Transformed code:', result.code);\nconsole.log('Source map:', result.map);","lang":"typescript","description":"Shows how to synchronously parse and transform Astro code using the sync wrapper."},"warnings":[{"fix":"Upgrade Node.js to ^18.18.0 or >=20.9.0.","message":"Dropped support for Node.js <18.18 (v1.0.0)","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Update @astrojs/compiler to >=0.27.0 (e.g., npm install @astrojs/compiler@latest).","message":"Requires @astrojs/compiler >=0.27.0 (v0.3.0)","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Update to v1.1.0 or later.","message":"CJS entry typo fixed in v1.1.0 - incorrect typing for cjs entry","severity":"gotcha","affected_versions":"<1.1.0"},{"fix":"Update to >=0.3.3.","message":"Crash in browser for earlier versions (fixed in v0.3.3)","severity":"gotcha","affected_versions":"<0.3.3"},{"fix":"Update to v1.1.1 to avoid potential issues with CJS bundlers.","message":"Older versions use require('cjs') internally; v1.1.1 refactored to use require directly in CJS context","severity":"deprecated","affected_versions":"<1.1.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use dynamic import() or convert to ESM and use import statements.","cause":"Using CommonJS require to import an ESM package.","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"},{"fix":"Run npm install @astrojs/compiler@>=0.27.0.","cause":"Missing peer dependency @astrojs/compiler.","error":"Cannot find module '@astrojs/compiler'"},{"fix":"Use import { parse } from 'astrojs-compiler-sync'.","cause":"Incorrect import (e.g., default import instead of named export).","error":"parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}