shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
steveb8n 2020-11-26T06:47:03.252Z

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

thheller 2020-11-26T08:53:59.253600Z

@steveb8n 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?

steveb8n 2020-11-26T08:54:56.253800Z

+ 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

thheller 2020-11-26T08:56:23.254Z

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

steveb8n 2020-11-26T08:56:28.254200Z

@thheller 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?

thheller 2020-11-26T08:56:31.254400Z

the :js-options have no effect here

steveb8n 2020-11-26T08:56:46.254600Z

good. I suspected as much

thheller 2020-11-26T08:56:58.254800Z

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

thheller 2020-11-26T08:57:18.255Z

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

thheller 2020-11-26T08:57:36.255200Z

run node manually and then require("uuid")

steveb8n 2020-11-26T08:57:44.255400Z

ok….

thheller 2020-11-26T08:58:11.255600Z

just as a test to see if that reproduces the error

steveb8n 2020-11-26T08:58:21.255800Z

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] } >

steveb8n 2020-11-26T08:58:34.256Z

can’t tell which impl was selected

thheller 2020-11-26T08:58:39.256200Z

ok and that is the same node as above?

steveb8n 2020-11-26T08:58:50.256400Z

good question….

thheller 2020-11-26T08:58:50.256600Z

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

steveb8n 2020-11-26T08:59:02.256800Z

I do have a different result on my machine vs CI

steveb8n 2020-11-26T08:59:25.257Z

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

thheller 2020-11-26T08:59:43.257200Z

thats what you should get

thheller 2020-11-26T09:00:00.257400Z

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

steveb8n 2020-11-26T09:00:08.257600Z

checking node version differences…

thheller 2020-11-26T09:00:18.257800Z

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

thheller 2020-11-26T09:00:34.258Z

it used to require a --esm flag or so

steveb8n 2020-11-26T09:02:32.258200Z

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

thheller 2020-11-26T09:04:10.258400Z

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.

thheller 2020-11-26T09:04:22.258600Z

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

steveb8n 2020-11-26T09:05:06.258800Z

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

thheller 2020-11-26T09:05:19.259Z

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

steveb8n 2020-11-26T09:05:39.259200Z

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

thheller 2020-11-26T09:06:18.259400Z

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

steveb8n 2020-11-26T09:06:36.259600Z

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

steveb8n 2020-11-26T09:06:44.259800Z

I’ll start by matching these up

thheller 2020-11-26T09:06:47.260Z

node -e "require('uuid')"

thheller 2020-11-26T09:07:35.260200Z

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

steveb8n 2020-11-26T09:08:05.260400Z

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

steveb8n 2020-11-26T09:08:29.260600Z

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

steveb8n 2020-11-26T09:08:33.260800Z

thanks 🙂

steveb8n 2020-11-26T09:40:46.261Z

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

steveb8n 2020-11-26T09:41:02.261200Z

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

steveb8n 2020-11-26T09:41:11.261400Z

thanks again 🙏

steveb8n 2020-11-26T06:47:37.252100Z

the lib is https://github.com/uuidjs/uuid

steveb8n 2020-11-26T06:47:58.252400Z

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

steveb8n 2020-11-26T06:49:02.252600Z

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

steveb8n 2020-11-26T06:49:13.252800Z

anyone dealt with this before?

steveb8n 2020-11-26T06:52:47.253Z

the require is…

steveb8n 2020-11-26T06:52:49.253200Z

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

steveb8n 2020-11-26T06:53:23.253400Z

{:target           :node-test
             :compiler-options {:optimizations :none}
             :js-options       {:entry-keys ["module" "main"]} ; using esm modules (for uuid npm dep) see <https://shadow-cljs.github.io/docs/UsersGuide.html#js-entry-keys>
             :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}

2020-11-26T12:53:07.262500Z

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.

scknkkrer 2020-11-26T14:13:07.263700Z

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

2020-11-26T14:22:09.264100Z

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!

scknkkrer 2020-11-26T14:22:40.264300Z

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

scknkkrer 2020-11-26T14:22:53.264500Z

Beside, re-frame.

2020-11-26T14:23:55.264700Z

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

scknkkrer 2020-11-26T14:24:52.264900Z

I need more purified template, I think.

scknkkrer 2020-11-26T14:25:02.265100Z

I need a simple job to do.

2020-11-26T14:25:59.265300Z

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