Skip to main content

React-Native & Clojurescript - ES6 Import/Export

How to use ES6 modules in Clojurescript.

By Darong MeanApril 30, 2018

using shadow-cljs .

Table: ES6 Import to CLJS Require1

ES6 ImportCLJS Require
import defaultExport from “module-name”;(:require [“module-name” :default defaultExport])
import * as name from “module-name”;(:require [“module-name” :as name])
import { export } from “module-name”;(:require [“module-name” :refer (export)])
import { export as alias } from “module-name”;(:require [“module-name” :rename {export alias}])
import { export1 , export2 } from “module-name”;(:require [“module-name” :refer (export1 export2)])
import { export1 , export2 as alias2 , […] } from “module-name”;(:require [“module-name” :refer (export1) :rename {export2 alias2}])
import defaultExport, { export [ , […] ] } from “module-name”;(:require [“module-name” :refer (export) :default defaultExport])
import defaultExport, * as name from “module-name”;(:require [“module-name” :as name :default defaultExport])
import “module-name”;(:require [“module-name”])

The :default option is currently only available in shadow-cljs, you can vote here to hopefully make it standard.

You can always use :as alias and then call alias/default if you prefer to stay compatible with standard CLJS in the meantime.