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
@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?
+ 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
why is your node setup using the module
entry? it should be using main
?
@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?
the :js-options
have no effect here
good. I suspected as much
the "shim" is literally only doing require("uuid")
. nothing else.
so when it is taking the browser entry that is something in your node setup
run node
manually and then require("uuid")
ok….
just as a test to see if that reproduces the error
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] } >
can’t tell which impl was selected
ok and that is the same node
as above?
good question….
you can do require.resolve("uuid")
to see
I do have a different result on my machine vs CI
> require.resolve(“uuid”) ‘/Users/steve/Documents/dev-personal/nextdoc-cloud/components-portable/node_modules/uuid/dist/index.js’ >
thats what you should get
you might have configured some node environment variable or so to prefer esm
checking node version differences…
I honestly don't know what the state of esm support in node is
it used to require a --esm
flag or so
it’ll take me a bit of time (docker) to check node versions. would that be a likely cause?
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.
so it might be something from the environment or your package.json
yeah ok. I will look into the package-lock as well. thanks for taking a first pass at this
As of Node.js 12.17.0, the --experimental-modules flag is no longer necessary to use ECMAScript modules (ESM).
I’ll touch base if I find out some clues that point at shadow instead of node/npm
if node
and require("uuid")
works then :node-test
output fill work too
my local machine is v12.12.0. CI (where it fails) is v13.2.0
I’ll start by matching these up
node -e "require('uuid')"
seems kinda weird that it picks the module
entry but then doesn't understand modules 😛
yeah. the world of npm is weird in many ways but so much gold in libs out there too
I’ve gotta go have dinner. I’ll report back conclusions
thanks 🙂
ok. it was the node version. works fine in v12 and fails in v13
I’ll stick with v12 since that’s what’s supported by AWS lambda
thanks again 🙏
the lib is https://github.com/uuidjs/uuid
from that error I can see that it’s using the wrong dist i.e. the browser variant
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
anyone dealt with this before?
the require is…
(:require ["uuid" :as uuid-js])
{: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}
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.
Any guide to combine Clojure
and Clojurescript
projects, with Shadow
?
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!
I don’t have a project, yet. Are there any good template for this ?
Beside, re-frame.
I like re-frame, it uses shadow cljs and has the Clojure setup built in, but there are probably others as well
I need more purified template, I think.
I need a simple job to do.
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