Fork me on GitHub
#shadow-cljs
<
2022-02-21
>
eploko02:02:19

Hey all, I get an error I seemingly can't resolve...

Failed to inspect file
  app/node_modules/fsevents/fsevents.node

it was required from
  app/node_modules/fsevents/fsevents.js

Errors encountered while trying to parse file
  app/node_modules/fsevents/fsevents.node
  {:line 1, :column 0, :message "Character '�' (U+FFFD) is not a valid identifier start char"}

eploko02:02:15

I build with :target :esm as some of the npm packages I use are esm-only.

eploko02:02:12

The full build config is:

{:target :esm
   :output-dir "resources/js/compiled/backend"
   :output-to "resources/js/compiled/backend/main.mjs"
   :modules {:main {:init-fn app.backend/main}}}

eploko02:02:12

The error comes from fsevents doing require('./fsevents.node') which fails as the thing is a native module...

eploko02:02:05

It there any way to tell shadow-clsj (or... who's actually implementing that require fn here?) to not parse *.node as potential js files?

eploko02:02:53

Hm, I was banging my head against this for a couple of days and, as soon as I posted the question here, I seemingly have found a solution: just saying adding :js-options {:js-provider :require} seems to resolve the issue. Hm...

eploko03:02:51

Well, no... it now fails trying to access WebSocket:

file:///...app/resources/js/compiled/backend/cljs-runtime/shadow.cljs.devtools.client.websocket.js:5
var socket = (new WebSocket(ws_url));
             ^

ReferenceError: WebSocket is not defined
    at shadow$cljs$devtools$client$websocket$start (file:///...app/resources/js/compiled/backend/cljs-runtime/shadow.cljs.devtools.client.websocket.js:5:14)
    at Object.attempt_connect_BANG_ (file:///...app/resources/js/compiled/backend/cljs-runtime/shadow.cljs.devtools.client.shared.js:482:128)
    at Object.shadow$cljs$devtools$client$shared$init_runtime_BANG_ [as init_runtime_BANG_] (file:///...app/resources/js/compiled/backend/cljs-runtime/shadow.cljs.devtools.client.shared.js:970:16)
    at file:///...app/resources/js/compiled/backend/cljs-runtime/shadow.cljs.devtools.client.browser.js:1230:36
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

thheller05:02:09

if you intend this to run in node you should set :js-options {:js-provider :import} in your build config

thheller05:02:23

and also :runtime :node (not in :js-options)

thheller05:02:53

otherwise defaults to :browser and trying to bundle everything (which is not required for node)

eploko00:02:37

Whoa, thanks for the heads-up 🙂 I was not aware of the :js-provider :import variant.

roklenarcic21:02:25

I’ve noticed that there are options in :devtools key in builds that are not in the user manual…

{:http-port          8022
                                          :http-resource-root "public"
                                          :http-root          "resources/public/js/test"}
is there additional documentation where it’s described how these work?