shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2021-06-23T09:10:24.237500Z

Hi, I never had the case so far. How to import a js module outside "node_modules" via its relative path like

import { Ziggy } from './ziggy.js';

2021-06-23T09:11:56.238700Z

I'll tried :require ["./ziggy.js" :refer [Ziggy]]

2021-06-23T09:12:58.239Z

I'm asking here and not on #clojurescript because I think Shadow-cljs offers more possibilities for imports, right?

2021-06-23T09:25:23.241Z

That all right, it works. I also found the :js-options :resolve who seems perfect to avoid complected relative paths. šŸ‘

thheller 2021-06-23T10:03:17.242Z

@admin055 do not use :resolve. if you have the file on the classpath (which you should) just use either the relative path or the full path (:require ["/some/file.js"]) following classpath rules

2021-06-23T12:04:22.243400Z

OK thanks for the advice and confirmation. Another question, I tried to import/require this lib ziggy-js but without success: https://github.com/tighten/ziggy/blob/main/src/js/index.js#L3

2021-06-23T12:06:04.244500Z

I have already tried what I usually do, i.e.

["ziggy-js" :refer [route]]

or

["ziggy-js" :default route]

2021-06-23T12:07:10.245Z

But it doesn't works. Any clue?

thheller 2021-06-23T12:17:31.245300Z

might be ["ziggy-js" :as route]

2021-06-23T12:35:00.246300Z

Yep it works. šŸ‘ The part with the REPL workflow to debug the imports is very interesting and useful. Thx

martinklepsch 2021-06-23T15:02:06.247300Z

Iā€™m trying to get Cypress working with some shadow-cljs builds but keep getting this error:

Cannot use import statement outside a module
Tried release and watch builds, both unsuccessful

erwinrooijakkers 2021-06-23T15:57:31.248600Z

Is it possible to import raw .jsx files? When I import as such:

["./surveyjs/widgets/RatingWidget.jsx" :refer [RatingWidget]]
I get: > cannot identify as cljs resource

erwinrooijakkers 2021-06-23T16:04:17.249Z

ah i think it needs to be preprocessed (https://shadow-cljs.github.io/docs/UsersGuide.html)

thheller 2021-06-23T17:36:28.249100Z

don't know what cypress is. where do you get this error? shadow doesn't generate import statements anywhere. unless you are using :target :esm?

erwinrooijakkers 2021-06-23T18:28:06.249600Z

That worked :thumbsup:

erwinrooijakkers 2021-06-23T18:28:36.249900Z

npx babel *.jsx --out-dir gen

Robert Pofuk 2021-06-23T18:50:50.252500Z

Hi! I have javascript hosted on different URL from application it self and it works ok for main module. When I have multiple modules then they are loaded from relative path to index.html. This problem I notices on mobile when packaging using cordova, main.js comes from https://example.com/main.js but then my module is loaded from http://127.0.0.1/module.js. Can I somehow adjust URLS for modules?

thheller 2021-06-23T18:57:14.252900Z

:asset-path controls that