thheller / shadow-cljs

ClojureScript compilation made easy
https://github.com/thheller/shadow-cljs
Eclipse Public License 1.0
2.25k stars 177 forks source link

Broken CommonJS Closure processing #204

Closed thheller closed 4 years ago

thheller commented 6 years ago

For :js-provider :require and :closure CommonJS files are processed by Closure.

Closure changed how CommonJS is rewritten by exporting everything under the .default property.

// some/file.js
exports.foo = "bar";

// used to generate
module$some$file.foo

// now it generates
module$some$file.default.foo

BUT their ES6 processing is "strict" in that you are only allowed to use the default export now.

// this is fine
import x from "some/file";
x.foo

// this is null
import { foo } from "some/file"
foo

import * as x from "some/file"
x => {default: {foo: "foo"}}
x.foo => null

Problem is that node_modules usually consists of CJS converted from ES6 by babel or webpack.

So GCC treats them as CJS but that breaks imports that otherwise work in webpack (or any other JS tool).

import { css } from "aphrodite"
// css is null
css(...)

// technically you should be using
import A from "aphrodite";
A.css(...)

Who is going to do that though if all the JS docs tell you to do the first kind of import?

This is either unfinished work from https://github.com/google/closure-compiler/pull/2729#issuecomment-351199344 or working as intended.

I'm not sure how to fix this properly without just skipping Closure for CommonJS entirely.

thheller commented 4 years ago

Nothing that can be done here except wait until the JS world settles on what they want to do.