Fork me on GitHub
#shadow-cljs
<
2019-07-06
>
mhuebert12:07:29

Hm, working on a :npm-module target, and requiring some JS files from cljs using (:require ["/abs-path-to-js" :as my-js]). Compiles, but when that js file is evaluated I get a ReferenceError: shadow$provide is not defined

mhuebert12:07:10

toying around, I added a shadow$provide = {}, then see another error - the pattern in these re-emitted js files is

shadow$provide.module$foo = function() {...}
module.exports = module$foo
..and module$foo is not defined

thheller12:07:12

the js file should be ES6+. commonjs doesn't work

thheller12:07:33

ie. import/export not module.exports/require

mhuebert13:07:09

I’m getting some weird errors working with js files that depend on other js files https://gist.github.com/mhuebert/6898da15723a26da485a984bc3249022

mhuebert14:07:21

one example fails at runtime, referencing a variable that isn’t defined except in the other js file. identity$$module$ftest$util instead of module$ftest$util.identity

mhuebert14:07:10

the other one fails at compile time:

import * as util from './util'
export const IDENTITY = (x) => util.identity(x)

thheller15:07:23

hmm yeah the problem there is the :npm-module target

thheller15:07:06

the direct JS support sort of only works in the browser since it sort of relies on having a shared global scope

thheller15:07:52

not sure about the closure compiler error though

thheller15:07:06

it might work with a newer closure compiler version

mhuebert15:07:52

hm ok. So using (js/require "..") would be more reliable

thheller15:07:23

yeah. I'm thinking about adding an option that skips the shadow-cljs transpilation of the JS files

thheller15:07:30

and just copies them to the output-dir as is

thheller15:07:40

so node can do the require stuff

mhuebert15:07:01

for what I am trying to do, I think that would be ideal

mhuebert15:07:20

I am trying to avoid an extra transpile step, the env I’m deploying to doesn’t support import/export

thheller15:07:29

but that requires a bit of work so for now I'd stick with js/require probably

mhuebert15:07:40

k. how do relative paths work with js/require in shadow?

thheller15:07:05

all files are in the :output-dir so whatever you require must be relative to that

mhuebert15:07:14

that’s simple