Fork me on GitHub
#shadow-cljs
<
2020-11-26
>
steveb8n06:11:03

Q: I’m struggling with an npm dep failing in nodejs CI tests. The error is opt/atlassian/pipelines/agent/build/node_modules/uuid/dist/esm-browser/index.js:1

steveb8n06:11:58

from that error I can see that it’s using the wrong dist i.e. the browser variant

steveb8n06:11:02

but I can’t work out how to get it to use the node variant instead. I’ve tried nearly everything in the docs about npm deps e.g. “module” entrypoints etc but no luck

steveb8n06:11:13

anyone dealt with this before?

steveb8n06:11:47

the require is…

steveb8n06:11:49

(:require ["uuid" :as uuid-js])

steveb8n06:11:23

{:target           :node-test
             :compiler-options {:optimizations :none}
             :js-options       {:entry-keys ["module" "main"]} ; using esm modules (for uuid npm dep) see 
             :output-to        "cljs-out/test/node-tests.js"
             :ns-regexp        "-test$"
             ; autorun does not return an exit code suitable for CI. CI tests are runs from node cli instead
             :autorun          false}

thheller08:11:59

@U0510KXTU opt/atlassian/pipelines/agent/build/node_modules/uuid/dist/esm-browser/index.js:1 is not an error. that is a filename. what is the actual error?

steveb8n08:11:56

+ node cljs-out/test/node-tests.js SHADOW import error /opt/atlassian/pipelines/agent/build/.shadow-cljs/builds/test-ci/dev/out/cljs-runtime/shadow.js.shim.module$uuid.js /opt/atlassian/pipelines/agent/build/node_modules/uuid/dist/esm-browser/index.js:1 export { default as v1 } from './v1.js'; ^^^^^^ SyntaxError: Unexpected token 'export' at wrapSafe (internal/modules/cjs/loader.js:1043:16) at Module._compile (internal/modules/cjs/loader.js:1091:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10) at Module.load (internal/modules/cjs/loader.js:976:32) at Function.Module._load (internal/modules/cjs/loader.js:884:14) at Module.require (internal/modules/cjs/loader.js:1016:19) at require (internal/modules/cjs/helpers.js:69:18) at /opt/atlassian/pipelines/agent/build/.shadow-cljs/builds/test-ci/dev/out/cljs-runtime/shadow.js.shim.module$uuid.js:3:30 at global.SHADOW_IMPORT (/opt/atlassian/pipelines/agent/build/cljs-out/test/node-tests.js:64:44) at /opt/atlassian/pipelines/agent/build/cljs-out/test/node-tests.js:1839:1

thheller08:11:23

why is your node setup using the module entry? it should be using main?

steveb8n08:11:28

@U05224H0W my naive reading of this is that the shim is running the browser impl when it’s in a nodejs build. Am I wrong about this?

thheller08:11:31

the :js-options have no effect here

steveb8n08:11:46

good. I suspected as much

thheller08:11:58

the "shim" is literally only doing require("uuid"). nothing else.

thheller08:11:18

so when it is taking the browser entry that is something in your node setup

thheller08:11:36

run node manually and then require("uuid")

thheller08:11:11

just as a test to see if that reproduces the error

steveb8n08:11:21

Welcome to Node.js v12.12.0. Type “.help” for more information. > require(“uuid”) { v1: [Getter], v3: [Getter], v4: [Getter], v5: [Getter], NIL: [Getter], version: [Getter], validate: [Getter], stringify: [Getter], parse: [Getter] } >

steveb8n08:11:34

can’t tell which impl was selected

thheller08:11:39

ok and that is the same node as above?

steveb8n08:11:50

good question….

thheller08:11:50

you can do require.resolve("uuid") to see

steveb8n08:11:02

I do have a different result on my machine vs CI

steveb8n08:11:25

> require.resolve(“uuid”) ‘/Users/steve/Documents/dev-personal/nextdoc-cloud/components-portable/node_modules/uuid/dist/index.js’ >

thheller08:11:43

thats what you should get

thheller09:11:00

you might have configured some node environment variable or so to prefer esm

steveb8n09:11:08

checking node version differences…

thheller09:11:18

I honestly don't know what the state of esm support in node is

thheller09:11:34

it used to require a --esm flag or so

steveb8n09:11:32

it’ll take me a bit of time (docker) to check node versions. would that be a likely cause?

thheller09:11:10

I don't know honestly. none of the js-options will do anything since node is responsible for picking the JS dependency. which you can see from the stacktrace.

thheller09:11:22

so it might be something from the environment or your package.json

steveb8n09:11:06

yeah ok. I will look into the package-lock as well. thanks for taking a first pass at this

thheller09:11:19

As of Node.js 12.17.0, the --experimental-modules flag is no longer necessary to use ECMAScript modules (ESM).

steveb8n09:11:39

I’ll touch base if I find out some clues that point at shadow instead of node/npm

thheller09:11:18

if node and require("uuid") works then :node-test output fill work too

steveb8n09:11:36

my local machine is v12.12.0. CI (where it fails) is v13.2.0

steveb8n09:11:44

I’ll start by matching these up

thheller09:11:47

node -e "require('uuid')"

thheller09:11:35

seems kinda weird that it picks the module entry but then doesn't understand modules 😛

steveb8n09:11:05

yeah. the world of npm is weird in many ways but so much gold in libs out there too

steveb8n09:11:29

I’ve gotta go have dinner. I’ll report back conclusions

steveb8n09:11:33

thanks 🙂

steveb8n09:11:46

ok. it was the node version. works fine in v12 and fails in v13

steveb8n09:11:02

I’ll stick with v12 since that’s what’s supported by AWS lambda

steveb8n09:11:11

thanks again 🙏

mrchance12:11:07

Hey! Is there a recommended way to hack on two libraries at once, similar to lein checkouts? I didn't really find anything besides some recommendations to just softlink part of the source tree.

mrchance13:11:04

Ah, I found something in the slack archive:

@lilactown just add the :source-paths and keep it in :dependencies. or you use the lein integration
Thanks, will try that first

mrchance13:11:04

Ah, I found something in the slack archive:

@lilactown just add the :source-paths and keep it in :dependencies. or you use the lein integration
Thanks, will try that first

scknkkrer14:11:07

Any guide to combine Clojure and Clojurescript projects, with Shadow ?

mrchance14:11:09

If you're using the re-frame template, there's a parameter to include a compojure server for fullstack development, that might offer a start!

scknkkrer14:11:40

I don’t have a project, yet. Are there any good template for this ?

scknkkrer14:11:53

Beside, re-frame.

mrchance14:11:55

I like re-frame, it uses shadow cljs and has the Clojure setup built in, but there are probably others as well

scknkkrer14:11:52

I need more purified template, I think.

scknkkrer14:11:02

I need a simple job to do.

mrchance14:11:59

Hm, then I'd just use the re-frame template for an example how the integration works (It's pretty straightforward), and then go with the reagent template: https://github.com/reagent-project/reagent-template