Cherry CLJS
raw JSON → 0.5.34 verified Fri May 01 auth: no javascript
Cherry is an experimental ClojureScript-to-ES6 module compiler that outputs readable, source-mapped .mjs files. It aims to reduce friction between ClojureScript and JavaScript tooling by producing ES6 modules that can be used directly with Node.js, Vite, and other modern JS toolchains. Unlike the official ClojureScript compiler, Cherry does not depend on Google Closure and is distributed as an NPM package. It supports macros, REPL, async/await, JSX via #jsx, and JS object destructuring. Version 0.5.34 is the latest; the project is experimental and not recommended for production use, with many bugs and frequent breaking changes.
Common errors
error Error: Cannot find module 'cherry-cljs' when trying to import ↓
cause Package is not installed or import path is incorrect.
fix
Run
npm install cherry-cljs@latest. Ensure import uses named export: import { cherry } from 'cherry-cljs'. error SyntaxError: The requested module 'cherry-cljs' does not provide an export named 'default' ↓
cause Wrong import style: default import used but package only exports named exports.
fix
Use
import { cherry } from 'cherry-cljs' instead of import cherry from 'cherry-cljs'. error CompilerException: Unsupported :require syntax ↓
cause Using old ClojureScript require syntax for JS modules.
fix
Use new syntax:
(:require ["module-name" :as alias]) or (:require ["module-name" :refer [symbol]]). Warnings
breaking Cherry is experimental and not recommended for production; APIs and output may change without notice. ↓
fix Pin a specific version and test thoroughly before upgrading.
gotcha Compiled output depends on 'cherry-cljs' runtime module. Breaking changes in the runtime may break compiled code. ↓
fix Ensure runtime version matches compiler version, or use lockfile.
deprecated The `cherry-cljs/core` subpath import was replaced by named export `core`. ↓
fix Use `import { core } from 'cherry-cljs'` instead.
gotcha Cherry does not support all ClojureScript features, e.g., some macros or interop patterns. ↓
fix Refer to issue tracker for known incompatibilities; consider Squint for CLJS syntax to JS compilation.
breaking Version 0.5.0 changed how require of JS modules works: now uses JavaScript import syntax in output. ↓
fix Update .cljs files to use the new require syntax: `(:require ["mod" :as mod])` instead of `(:require ["mod" :refer [foo]])` for default imports.
gotcha Source maps may not always be accurate in development mode due to experimental nature. ↓
fix Use `npx cherry run --debug` for better error messages, but expect occasional mismatches.
Install
npm install cherry-cljs yarn add cherry-cljs pnpm add cherry-cljs Imports
- cherry wrong
import cherry from 'cherry-cljs'correctimport { cherry } from 'cherry-cljs' - compileString wrong
const compileString = require('cherry-cljs/compileString')correctimport { compileString } from 'cherry-cljs' - cljs.core wrong
import * as core from 'cherry-cljs/core'correctimport { core } from 'cherry-cljs'
Quickstart
mkdir cherry-test && cd cherry-test
npm init -y
npm install cherry-cljs@latest
cat > example.cljs << 'EOF'
(ns example
(:require ["fs" :as fs]
["url" :refer [fileURLToPath]]))
(prn (fs/existsSync (fileURLToPath js/import.meta.url)))
(defn foo [{:keys [a b c]}]
(+ a b c))
(js/console.log (foo {:a 1 :b 2 :c 3}))
EOF
npx cherry run example.cljs