cljsjs

jannis 2018-02-28T10:24:41.000325Z

Hi folks! I’ve been working on packaging some JS libraries (apollo-client, react-apollo etc.) for cljsjs. I’ve only been successful with UMD bundles. CommonJS bundles typically complain about exports not being defined (they all seem to start with Object.defineProperty(exports, '__esModule', ...). Is this expected? Are there some examples based on CommonJS bundles that I could explore?

jmckitrick 2018-02-28T13:43:42.000048Z

I’m having exactly the same issue, @jannis

jannis 2018-02-28T14:18:05.000680Z

@jmckitrick I’m pausing my efforts on this right now. I think I’ve patched the rollup and build configs of ~6-8 packages now to get to react-apollo and there are still a few missing. 😕

jmckitrick 2018-02-28T14:18:26.000782Z

Ugh, that’s frustrating.

jannis 2018-02-28T14:19:55.000587Z

Just a little. 😉

jmckitrick 2018-02-28T14:20:42.000251Z

Are you committed to the cljsjs method?

jannis 2018-02-28T14:21:03.000608Z

I’m confident all changes involving apollo are really upstream mistakes and will be accepted as PRs. But the official graphql library needs to be built differently and I’m not sure I can convince them to add another built command just for us. 😉

jannis 2018-02-28T14:22:15.000132Z

@jmckitrick I’d rather solve it via :npm-deps but there are still problems with indexing the npm packages I’m trying to import.

jmckitrick 2018-02-28T14:23:04.000285Z

Can you elaborate, @jannis? I’m new to :npm-deps so anything I can learn is good.

jmckitrick 2018-02-28T14:23:20.000510Z

Specifically, indexing.

jannis 2018-02-28T14:23:32.000456Z

Ha, if only I knew anything about it! 🙂

jannis 2018-02-28T14:23:49.000278Z

You know what :npm-deps is?

jmckitrick 2018-02-28T14:24:17.000616Z

Yes, I’m experimenting with it now, when I couldn’t get a cljsjs package to work 😉

jmckitrick 2018-02-28T14:24:58.000423Z

I followed the directions, and both online extern extraction tools crapped out, saying the namespace I wanted was not found.

jmckitrick 2018-02-28T14:25:16.000113Z

I’m going to start a blog and explain this once I figure it out lol

jannis 2018-02-28T14:25:54.000706Z

Hehe, ok. So adding :npm-deps aims to allow importing any NPM packages so that you can (require [react :refer [createElement]]) them from a CLJS namespace. So far so good.

jannis 2018-02-28T14:26:20.000180Z

That works fine with some/many packages. I’ll give you an example where it doesn’t currently work: graphql.

jannis 2018-02-28T14:28:01.000577Z

The package.json of graphql has a "module": "index.mjs" entry, which CLJS currently doesn’t support (this is a theory, but given that it works once you rename it to index.js, I may be guessing right). As a result, goog.require('graphql') will not be able to resolve the module when loading the CLJS app in the browser.

jannis 2018-02-28T14:28:22.000668Z

Because graphql isn’t indexed and added via goog.addDependency.

jmckitrick 2018-02-28T14:29:04.000636Z

Ah, ok. I’ve so far not used goog.require

jannis 2018-02-28T14:30:11.000567Z

It’s what CLJS uses under the hood to link the JS modules built for all the CLJS namespaces. And for external JS libraries.

jannis 2018-02-28T14:30:24.000698Z

I think.

jmckitrick 2018-02-28T14:30:26.000303Z

Right.

jmckitrick 2018-02-28T14:30:59.000017Z

Have you seen this article? http://blob.tomerweller.com/reagent-import-react-components-from-npm

jannis 2018-02-28T14:31:16.000391Z

Shouldn’t really matter much, since it would work fine if it all required dependencies are added via cljs_deps.js.

jannis 2018-02-28T14:33:59.000805Z

@jmckitrick Not until now. But yeah, if you can bundle all your dependencies together nicely that’s one way you could do it. Make sure to define externs though so optimized builds don’t break.

jmckitrick 2018-02-28T14:34:04.000281Z

Hmm. Well, I wasn’t able to get the 2 components I needed to import in the ‘usual’ ways. Maybe I’m doing them wrong. But I saw your comment on the error with CommonJS modules, and that’s what I saw as well.