Fork me on GitHub
#shadow-cljs
<
2018-12-03
>
romdoq09:12:23

When I starting using re-frame in my project, the release build of my browser npm module started erroring with Cannot read property 'navigator' of undefined during import of the module. I've tracked down that goog.base.js sets $ = window.global at the end, but window.global is undefined. I'm not sure if it's something shadow-cljs is doing, or something webpack is doing, or both. Any ideas how to proceed?

thheller09:12:54

@mel.collins which version are you on? I fixed a related issue recently

romdoq09:12:31

hah, I could've sworn I updated shadow-cljs last week, but apparently I was still on 2.6.10. The lastest version does indeed Just Work™, thanks!

Logan Powell13:12:15

Is there a way to bundle all dependencies with a :node-library or :npm-module as is done with :web-worker true?

thheller13:12:36

not sure how :web-worker is relevant to the bundling but all dependencies for node is not possible

Logan Powell13:12:57

Gotcha, thank you.

thheller13:12:30

just didn't have time to work on it. also not totally convinced that it should be done.

shaunlebron14:12:29

i used shadow-cljs yesterday to bundle cljs pretty-printer into a node.js project

shaunlebron14:12:08

(i couldn’t figure out how to produce a commonjs module file from native cljs compiler)

shaunlebron14:12:29

love it, it just worked

shaunlebron14:12:11

i wanted to prevent confusion by prepending an // Auto-generated comment to the output file: https://github.com/shaunlebron/highlight-tree-sitter/blob/master/shadow-cljs.edn#L6

shaunlebron14:12:18

is that possible?

thheller14:12:36

sure but don't forget \n

thheller14:12:06

hmm actually no I don't think :node-library respects that option

shaunlebron14:12:55

i suppose a umd target would also work for my use-case

shaunlebron14:12:36

oh, umd isn’t a separate target

thheller14:12:09

still haven't done any work on the umd stuff

thheller14:12:14

its complicated

thheller14:12:28

open a ticket about the prepend stuff. I'm barely at the PC currently and didn't get much done the past few weeks

shaunlebron14:12:50

np, great work on all this

pez14:12:33

OT, but, what is cljs pretty printer, @shaunlebron?

shaunlebron14:12:25

just wanted to print js arrays as s-expressions

pez14:12:41

OK, thanks. I thought it was maybe something new I had to look at. 😃

pez14:12:50

That's cool. Will you try get that into Atom to replace the current regex based tokenizer?

shaunlebron14:12:20

tree-sitter is actually built for atom

shaunlebron14:12:53

it’s available for some langs, js included. clojure is being worked on

pez14:12:04

:thumbsup:

hoopes17:12:29

Hi, I'm building my cljs to js for https://storybook.js.org in accordance with https://github.com/shadow-cljs/examples/blob/master/cljs-storybook/shadow-cljs.edn . I'd like to be able to see my sourcemaps, but the URLs are something like //# sourceMappingURL=cljs.core.async.impl.buffers.js.map, which is not where they're actually served from. Accd to the user guide, :source-map-path doesn't have any effect at all - is there a solution to this? Thanks very much!

thheller17:12:16

@hoopes the problem is not with shadow-cljs. the problem is that the code is processed further by storybook (webpack I believe). it must read the source maps and apply them to its output

thheller17:12:19

no idea how to do that

hoopes17:12:46

got it - sorry for the noise, i'll track it down. thanks very much!

hoopes17:12:42

cool, i was just looking through storybook stuff to figure out how to hook into their webpack config

hoopes17:12:57

(if i could do it inline, that would be ok too...)

aisamu18:12:27

Hi! I'm running into some differences on the runtime behavior of require between :npm-module and :browser-test targets. Given the sample import ["module/folder/file-with-default-function.js" :as file :default function], here's what the names get assigned to:

|          | :browser-test                          | :npm-module           |
|----------+----------------------------------------+-----------------------|
| file     | Object{default: function(args){ ... }} | function(args){ ... } |
| function | function(args){ ... }                  | undefined             |
Is that expected? The current workaround is a shim cljs file that checks for the existence of a default and binds the var to that instead

thheller18:12:31

@aisamu when using :npm-module it emits a straight up require("module/folder/file-with-default-function.js") call. however that is filled in I cannot control

thheller18:12:46

you can try setting :js-options {:prefer-esm true} in the :browser-test build

thheller18:12:58

it might then behave like :npm-module

thheller18:12:23

problem is that each package does pretty much their own shit regarding packaging

thheller18:12:40

and not all modules play well when the esm entries are used

thheller18:12:04

still need to figure out what kind of magic webpack is doing

aisamu18:12:20

If :js-options is located at the root of the build config (next to :target), then the result is the same 😕

thheller18:12:02

how is the :npm-module code loaded?

thheller18:12:08

webpack/node?

aisamu18:12:12

Through webpack, yup

thheller18:12:13

"module/folder/file-with-default-function.js" which module is this?

thheller18:12:59

or more importantly how is it consumed from the JS side?

aisamu18:12:15

It's a standard ES6 file with a small fn:

export default (args) => {
  return ...
}

thheller18:12:20

I think that has something to do with how requires are handled internally

thheller18:12:31

is it your file?

thheller18:12:47

then load it directly

aisamu18:12:11

That's how it was initially done, but it was breaking webpack

thheller18:12:25

hmm yeah I think :npm-module is a problem for this

thheller18:12:21

hmm how is webpack configured? they have a setting for this. maybe you are not using the "new" default behavior?

thheller18:12:32

I tried matching what the latest webpack does

aisamu18:12:41

It's a rather large existing webpack 3.11.0 project. Is there something specific I should look for?

thheller18:12:08

ah webpack 4 changed how some of that works

thheller18:12:26

so it might just be webpack3?

aisamu18:12:50

Oh, that'd explain it! If that's the case, sorry for the noise!

thheller18:12:49

the result in :browser-test looks correct to me. not sure about webpack and :npm-module

👌 4
thheller18:12:53

but I suspect its the interop between the require,shadow-cljs and webpack

thheller18:12:17

there are a few rough edges like that

aisamu18:12:16

Sure thing! Thanks for the help! I'll use the shims while we migrate to 4 🙂

thheller18:12:41

you could just write your .js file as commonjs

4
thheller18:12:45

that should solve the issue 😉

souenzzo20:12:20

Should I care about this warnings?

------ WARNING #2 --------------------------------------------------------------
 File: com/cognitect/transit/impl/writer.js:256:8

 variable isObject is undeclared
--------------------------------------------------------------------------------

------ WARNING #3 --------------------------------------------------------------
 File: fulcro_css/css_implementation.cljc:212:56

 variable garden is undeclared
--------------------------------------------------------------------------------

thheller20:12:20

@souenzzo no. can be ignored

thheller20:12:38

not the issue I had reported or the java warning

thheller20:12:53

so 1.12 should have fixed your issue already

vigilancetech21:12:09

yes, seems to do the trick. Thanks!

vigilancetech22:12:54

okay, now does anyone see a problem with this?

shadow-cljs - config: /home/kevin/0work/guardian-dashboard/shadow-cljs.edn  cli version: 2.7.6  node: v8.12.0
shadow-cljs - starting ...
Dec 03, 2018 2:28:19 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.8.Final
Dec 03, 2018 2:28:19 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.8.Final
shadow-cljs - HTTP server for :client available at 
shadow-cljs - server version: 2.7.6
shadow-cljs - server running at 
shadow-cljs - socket REPL running on port 42319
shadow-cljs - nREPL server started on port 45695
and
Starting Nmap 7.70 (  ) at 2018-12-03 14:38 PST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00016s latency).
Other addresses for localhost (not scanned): ::1
Not shown: 998 closed ports
PORT     STATE SERVICE
631/tcp  open  ipp
8080/tcp open  http-proxy

Nmap done: 1 IP address (1 host up) scanned in 0.65 seconds
(the latter was done with the -Pn flag) And cider won't connect with merely the "failed" error (nothing else, and doesn't get to the point where it even creates the nrepl message buffer even tho its enabled).

thheller22:12:42

not sure what I'm supposed to be seeing?

vigilancetech22:12:17

well, shouldn't there be a port open for the nrepl server for instance?

thheller22:12:20

try nc localhost 45695 or whatever port is shown

thheller22:12:28

or just configure a fixed port

thheller22:12:01

no idea how nmap scans or what -Pn means

vigilancetech22:12:43

I think it does all the ports rather than just the common ones

thheller22:12:54

only need to test one port

thheller22:12:28

the port that is shown on startup. it will either use that one or nothing. its not gonna report one but then use another

thheller22:12:37

no point in scanning everything

thheller22:12:56

given that is also didn't show 9630 it doesn't seem be a useful scan

thheller23:12:10

if you have lein installed you can also do lein repl :connect localhost:<the-port> without a project