Clojurians
#cljs-dev
<
2016-04-09
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

dnolen20:04:42

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

dnolen20:04:01

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

roman01la20:04:06

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

roman01la20:04:31

I'll duplicate a message here and mention her

dnolen20:04:57

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

dnolen20:04:25

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

roman01la20: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 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.

roman01la20:04:02

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

maria20:04:44

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

roman01la20: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

roman01la20:04:31

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

roman01la20:04:05

I’ll setup a quick project to reproduce

maria20:04:54

is the logger module part of your build config?

maria20:04:46

@roman01la: ^

roman01la21: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}

roman01la21:04:37

logger.js

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

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

roman01la21:04:38

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

dnolen21:04:41

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

dnolen21:04:53

I thought I suggested that in the ticket

dnolen21:04:09

stop munging valid keywords for > ECMA-262

roman01la21:04:25

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

roman01la21:04:29

let me check the output

roman01la21: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.

roman01la21: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)}
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

roman01la21:04:07

logger.js default export looks fine

roman01la21:04:42

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

maria21:04:33

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

roman01la22:04:18

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

roman01la22:04:26

foreign libs are being filtered out by module type

roman01la22:04:48

changing that line to

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

roman01la22: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

roman01la22:04:41

that’s why es6 + cjs fails

dnolen22:04:01

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