Fork me on GitHub

@roman01la: you probably want to direct some of your questions at Maria Geller when she is around.


we have CommonJS processing built in - did you read over her Google Summer of Code blog series?

Roman Liutikov20:04:06

@dnolen: yes. I think all of them. Also watched her talk on compiler, very helpful btw

Roman Liutikov20:04:31

I'll duplicate a message here and mention her


far as I know we use the same code as that Closure flag so I don’t see at the moment why there should be a discrepancy


@roman01la: the place to look is closure.clj it’s easy to spot the CJS & ES6 module related stuff

Roman Liutikov20:04:48

@maria: duplicating this for you > Does anybody know why ClojureScript fails to load a foreign lib if it is ES6 module which imports CommonJS module? Closure Compiler allows mixing of different module types I actually tried to compile this directly with GCC and it compiles fine with —process_common_js_modules flag specified. Not sure, but it seems like compiler settings in ClojureScript lacks this flag.

Roman Liutikov20:04:02

> it also fails to compile CJS module which imports ES6 module


@roman01la: how does it fail? do you get any errors/warnings? do you maybe have an example repo to reproduce the problem?

Roman Liutikov20:04:36

@maria: here’s the error > ERROR: JSC_ES6_MODULE_LOAD_ERROR. Failed to load module "./logger" at my-modular-lib/index.js line 1 : 10

Roman Liutikov20:04:31

btw, it doesn’t matter if es6 imports cjs or vice versa, the error always the same

Roman Liutikov20:04:05

I’ll setup a quick project to reproduce


is the logger module part of your build config?

Roman Liutikov21:04:48

@maria: yes, here’s foreign libs part

{:file "my-modular-lib/logger.js"
  :provides ["logger"]
  :module-type :commonjs}
 {:file "my-modular-lib/index.js"
  :provides ["msglogger"]
  :module-type :es6}

Roman Liutikov21:04:37


exports.default = function log(msg) {
  return console.log(msg);
import log from './logger';

export function logMsg(msg) {
  return log(msg);

Roman Liutikov21:04:38

@maria: notice, that logger.js follows ES6 modules semantics, it exports to default which is what ES6 module expects when importing


@roman01la: oh right, but isn’t this possibly addressed by my point about respecting the Closure language mode?


I thought I suggested that in the ticket


stop munging valid keywords for > ECMA-262

Roman Liutikov21:04:25

@dnolen: oh, I totally forgot about that default thing, because for me this is a separate issue

Roman Liutikov21:04:29

let me check the output

Roman Liutikov21:04:58

@dnolen: hmm, no, looks like this is a different thing. The issue with munging is related to ClojureScript code, but this one is about JS modules. I believe they are processed only by GCC.

Roman Liutikov21:04:35

here’s the output logger.js

goog.provide("module$my_modular_lib$logger");module$my_modular_lib$logger["default"]=function log(msg){return console.log(msg)}
goog.provide("module$my_modular_lib$index");import log from"./logger";function logMsg$$module$my_modular_lib$index(msg){return log(msg)}module$my_modular_lib$index.logMsg=logMsg$$module$my_modular_lib$index

Roman Liutikov21:04:07

logger.js default export looks fine

Roman Liutikov21:04:42

but an import in index.js is not resolved, because it throws an error when compiling


@roman01la: taking a look now. will let you know if I figure out what the problem is 😉

Roman Liutikov22:04:18

@maria: I think I found where’s the problem.

Roman Liutikov22:04:26

foreign libs are being filtered out by module type

Roman Liutikov22:04:48

changing that line to

(filter #(or (= (:module-type %) :es6)
                    (= (:module-type %) :commonjs)))
makes build pass successfully

Roman Liutikov22:04:29

so it seems like compilation runs for every module in foreign libs, but every run takes modules of only one type: amd or cjs or es6, but not multiple

Roman Liutikov22:04:41

that’s why es6 + cjs fails


@roman01la: feel free to add this information to the ticket