Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs with prefix namespaces & co. #874

Closed
green-coder opened this issue Apr 23, 2021 · 9 comments
Closed

Bugs with prefix namespaces & co. #874

green-coder opened this issue Apr 23, 2021 · 9 comments

Comments

@green-coder
Copy link

Minimal project to reproduce it: https://github.com/green-coder/shadow-cljs-namespace-party

shadow-cljs watch app

Then go to http://localhost:3000/

2 problems:

  • one is the error displayed,
  • the other one is the nil value printed.

image

@thheller
Copy link
Owner

You get a warning for this?


------ WARNING #1 - :ns-var-clash ----------------------------------------------
 File: /mnt/c/Users/thheller/code/tmp/shadow-cljs-namespace-party/src/a/b.cljs:3:1
--------------------------------------------------------------------------------
   1 | (ns a.b)
   2 |
   3 | (def c "c")
-------^------------------------------------------------------------------------
 Namespace a.b.c clashes with var a.b/c
--------------------------------------------------------------------------------
   4 |
--------------------------------------------------------------------------------

This is a known limitation in CLJS and not shadow-cljs related at all.

@thheller
Copy link
Owner

For the charset warning add <meta charset="utf-8"> to your html head.

@thheller
Copy link
Owner

FWIW Chrome shows a better error. Not sure why Firefox does not show the actual error message on load.

2021-04-23--14-49

thheller added a commit that referenced this issue Apr 23, 2021
somehow only showed up once for compile but not during watch

fixes #874
@green-coder
Copy link
Author

None of compile and watch had shown any warning with v2.12.5 :

➜  shadow-cljs-namespace-party git:(master) shadow-cljs compile app
shadow-cljs - config: /Users/vincent/code/nws/shadow-cljs-namespace-party/shadow-cljs.edn
shadow-cljs - starting via "clojure"
WARNING: When invoking clojure.main, use -M
[:app] Compiling ...
[:app] Build completed. (46 files, 0 compiled, 0 warnings, 1.35s)
➜  shadow-cljs-namespace-party git:(master) shadow-cljs watch app  
shadow-cljs - config: /Users/vincent/code/nws/shadow-cljs-namespace-party/shadow-cljs.edn
shadow-cljs - starting via "clojure"
WARNING: When invoking clojure.main, use -M
shadow-cljs - HTTP server available at http://localhost:3000
shadow-cljs - server version: 2.12.5 running at http://localhost:9630
shadow-cljs - nREPL server started on port 53824
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (121 files, 0 compiled, 0 warnings, 1.81s)

This is a known limitation in CLJS and not shadow-cljs related at all.

TIL .. I did not know that limitation.

Thank you for being so reactive. 👍

@thheller
Copy link
Owner

I got the warnings on the first compile but after caching it didn't warn. Not exactly sure why but it is fixed in master.

@green-coder
Copy link
Author

green-coder commented Apr 23, 2021

One explanation could be that the warning is non-deterministic, that somehow it depends on the source code parsing order?

There is a warning when a variable is conflicting with a namespace, is there a warning when a namespace conflicts with a variable?

@thheller
Copy link
Owner

That is possible yes. In general the namespaces and defs are layed out as nested JS objects so basically you'd have

a.b.c.d = "foo";
a.b.c = "bar";

So in this loading order the a.b.c.d is lost since the a.b.c overwrites it. If you load in different order that clash may actually work but could then break on hot-reload or so. In general the clash should be avoided to rule out strange behaviour.

@green-coder
Copy link
Author

The following compiled form could potentially be conflict free:

a.b.c.__SLASH__.d = "foo";
a.b.__SLASH__.c = "bar";

But I guess that the solution is not as simple as it looks, and it is probably related to the CLJS compiler.

@thheller
Copy link
Owner

Yes, if I was going to rewrite how the CLJS compiler works I'd change how namespaces are organized to avoid such conflicts. It does however require rewriting the CLJS compiler a little bit and is not something I can do via shadow-cljs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants