This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-09
Channels
- # admin-announcements (1)
- # boot (225)
- # braid-chat (1)
- # cider (25)
- # cljs-dev (35)
- # cljsrn (1)
- # clojars (6)
- # clojure (81)
- # clojure-berlin (1)
- # clojure-dev (21)
- # clojure-france (2)
- # clojure-japan (6)
- # clojure-poland (1)
- # clojure-russia (10)
- # clojure-uk (3)
- # clojurescript (121)
- # code-reviews (1)
- # core-async (4)
- # core-logic (2)
- # cursive (15)
- # datomic (8)
- # hoplon (4)
- # jaunt (112)
- # jobs-discuss (35)
- # om (41)
- # parinfer (8)
- # re-frame (3)
- # reagent (4)
- # ring (2)
- # untangled (38)
@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?
@dnolen: yes. I think all of them. Also watched her talk on compiler, very helpful btw
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
@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 https://github.com/google/closure-compiler/wiki/JS-Modules 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.
> 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?
@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
btw, it doesn’t matter if es6 imports cjs or vice versa, the error always the same
I’ll setup a quick project to reproduce
@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}
logger.js
exports.default = function log(msg) {
return console.log(msg);
};
index.js
import log from './logger';
export function logMsg(msg) {
return log(msg);
};
@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?
@dnolen: oh, I totally forgot about that default
thing, because for me this is a separate issue
let me check the output
@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.
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)}
index.js
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
logger.js
default export looks fine
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 😉
@maria: I think I found where’s the problem.
@maria: here https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L1501
foreign libs are being filtered out by module type
changing that line to
(filter #(or (= (:module-type %) :es6)
(= (:module-type %) :commonjs)))
makes build pass successfullyso 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
that’s why es6 + cjs fails
@roman01la: feel free to add this information to the ticket