Fork me on GitHub
#shadow-cljs
<
2023-03-03
>
Maris16:03:48

We have some cljs tests. They no longer work from lein doo.

Maris16:03:53

Library name must be specified as a symbol in :require / :require-macros; offending spec: ["dropzone" :refer [Dropzone]]

thheller17:03:00

that is not a shadow-cljs error message. so can't tell you what that is about

thheller17:03:47

IIRC lein doo uses the CLJS compiler directly, so it might just not support npm dependencies. shadow-cljs has plenty of testing options you can use instead

đź‘Ť 2
Maris17:03:52

HeadlessChrome 0.0.0 (Mac OS X 10.15.7) ERROR
  {
    "message": "Uncaught ReferenceError: global is not defined\nat test.js:8:15\n\nReferenceError: global is not defined\n    at test.js:8:15",
    "str": "Uncaught ReferenceError: global is not defined\nat test.js:8:15\n\nReferenceError: global is not defined\n    at test.js:8:15"
  }

Maris18:03:14

I tried to run karma but it didn’t work. :test {:target :karma :output-to "target/cljs-test-output/test.js"}

Maris18:03:32

Why is global undefined? It compiled just fine npx shadow-cljs compile test - created test.js file

thheller18:03:15

@maris.orbidans I don't know. global is not generally a thing in browser based builds. is your code trying to access js/global in some way? what is in line 8 of the test file?

thheller18:03:40

for me it is goog.global = this || self;?

Maris19:03:24

goog.global = global;

thheller22:03:10

this should not be like that. which version do you use?

thheller22:03:47

are you replacing goog/base.js in some way? are you messing with the expected closure-library version in some way?

Maris22:03:33

[thheller/shadow-cljs "2.21.0" :exclusions [com.google.errorprone/error_prone_annotations
                                                                               org.slf4j/slf4j-api
                                                                               nrepl]]

Maris22:03:41

"2.21.0"

Maris22:03:23

I tried to change the line to goog.global = this || self; and all tests worked

Maris22:03:06

[org.clojure/clojurescript "1.11.60" :exclusions [com.google.code.findbugs/jsr305
                                                                                     com.google.errorprone/error_prone_annotations
                                                                                     com.google.javascript/closure-compiler-unshaded]]

Maris22:03:33

there was dependency conflict ^ com.google.javascript/closure-compiler-unshaded

thheller22:03:09

why are you doing all this?

thheller22:03:31

I mean exclusions and that stuff?

Maris22:03:52

because of dependency conflicts.

thheller22:03:27

well, but why are you fixing them in the place that is supposed to bring in the proper versions?

thheller22:03:42

why not exclude them at the point where the "faulty" ones are introduced?

thheller22:03:59

I mean there shouldn't be a clojurescript dependency at all

thheller22:03:08

but it is fine if you have it

thheller22:03:18

but regardless

thheller22:03:25

what is the closure library version you get?

thheller22:03:07

I'm assuming you have :lein true or :lein {:profiles "+foo"} in your shadow-cljs.edn and manage all dependencies in project.clj?

Maris22:03:31

[org.clojure/google-closure-library “0.0-20211011-0726fdeb”]

Maris22:03:29

It is shadow-cljs that pulls in different version of com.google.javascript/closure-compiler-unshaded

Maris22:03:32

[org.clojure/google-closure-library-third-party “0.0-20211011-0726fdeb”]

thheller22:03:10

yes, ok my bad. this is the closure library version you are supposed to be getting

thheller22:03:52

please rm -rf target/cljs-test-output and rm -rf .shadow-cljs/builds

thheller22:03:02

then npx shadow-cljs compile test

thheller22:03:19

check line 8, verify that it is still the incorrect line?

thheller22:03:55

if so, run npx shadow-cljs clj-repl

thheller22:03:04

then ( "goog/base.js")

thheller22:03:35

should be a url pointing to the file from the closure-library

Maris22:03:49

the line is correct now goog.global = this || self;

thheller22:03:22

then the previous file likely wasn't from a :target :karma build

thheller22:03:36

maybe some old file or a mixed up path?

Maris22:03:05

maybe… it works now 🙂 thank you

Maris19:03:16

There is only single file in cljs-test-output. Does it need some other files? var CLOSURE_BASE_PATH = 'js/cljs-runtime/' This folder is in ./.shadow-cljs/builds/browser-repl/js/cljs-runtime

Maris19:03:27

There is no js/global anywhere in our code.

thheller22:03:47

the files in .shadow-cljs/builds/browser-repl are from the browser-repl build. they are in no way related to the test build. they'll be in .shadow-cljs/builds/test

Stuart22:03:31

Hi, I'm trying to use an npm package React date picker , here: The docs say: >

import React, { useState } from 'react';
> import DatePicker from 'react-date-picker';
I've installed it via npm install react-date-picker Then my requires look like this:
(:require ["react" :refer (useState)]
          ["react-date-picker" :refer (DatePicker)])
But I get the error > Failed to inspect file > /home/stuart/Source/Finance-Planner/Frontend/node_modules/react-calendar/dist/Calendar.css > > it was required from > /home/stuart/Source/Finance-Planner/Frontend/node_modules/react-date-picker/dist/entry.js > > Errors encountered while trying to parse file > /home/stuart/Source/Finance-Planner/Frontend/node_modules/react-calendar/dist/Calendar.css > {:line 1, :column 1, :message "primary expression expected"} I can confirm those files exist. What have I done wrong ?

thheller23:03:14

shadow-cljs does not support bundling css files. so libraries that attempt to import css will fail by default.

thheller23:03:51

you can set :js-options {:ignore-asset-requires true} in the build config which will just ignore them

thheller23:03:43

and run the external file through webpack or any other JS bundler that supports CSS

Stuart23:03:04

Thanks! I'll have a look