Fork me on GitHub
#shadow-cljs
<
2021-06-23
>
Michaël Salihi09:06:24

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';

Michaël Salihi09:06:56

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

Michaël Salihi09:06:58

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

Michaël Salihi09:06:23

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

thheller10:06:17

@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

Michaël Salihi12:06:22

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

Michaël Salihi12:06:04

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

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

or

["ziggy-js" :default route]

Michaël Salihi12:06:10

But it doesn't works. Any clue?

thheller12:06:31

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

Michaël Salihi12:06:00

Yep it works. 👍 The part with the REPL workflow to debug the imports is very interesting and useful. Thx

martinklepsch15:06:06

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

thheller17:06:28

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?

erwinrooijakkers15:06:31

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

2
erwinrooijakkers18:06:06

That worked :thumbsup:

erwinrooijakkers18:06:36

npx babel *.jsx --out-dir gen

Robert Pofuk18:06:50

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?

thheller18:06:14

:asset-path controls that