2

I am getting this error when trying to build a Clojurescript project with shadow-cljs. I've tried looking for syntax errors as described here but I can get the same the error with a single line and a single import although not all imports cause the same error.

This compiles:

(ns campfire.core)

(defn init [] (println "ok"))

This doesn't:

(ns campfire.core
  (:require ["bugout" :as b]))

(defn init [] (println "ok"))

The output from the above example is:

shadow-cljs - config: /home/ru/Projects/campfire/shadow-cljs.edn
shadow-cljs - HTTP server available at http://localhost:3000
shadow-cljs - server version: 2.11.18 running at http://localhost:9630
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :frontend
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build failure:
The required JS dependency "readable-stream/writable.js" is not available, it was required by "node_modules/stream-browserify/index.js".

Dependency Trace:
        campfire/core.cljs
        node_modules/bugout/index.js
        node_modules/bs58check/index.js
        node_modules/create-hash/browser.js
        node_modules/cipher-base/index.js
        node_modules/stream-browserify/index.js

Searched for npm packages in:
        /home/ru/Projects/campfire/node_modules

See: https://shadow-cljs.github.io/docs/UsersGuide.html#npm-install

package.json

{
  "name": "campfire",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "build": "shadow-cljs release frontend"
  },
  "devDependencies": {
    "shadow-cljs": "2.11.18"
  },
  "dependencies": {
    "bugout": "^0.0.10",
    "webtorrent": "^0.114.1"
  }
}

shadow-cljs.edn

{:source-paths
 ["src/dev"
  "src/main"
  "src/test"]

 :dependencies
 []

 :dev-http {3000 "public"}
 :nrepl {:port 8777}
 :builds
 {:frontend
  {:target  :browser
   :modules {:main {:init-fn campfire.core/init}}}}}

I've seen similar build errors that were fixed by clearing .shadow-cljs etc and rebuilding but nothing like that seems to be helping. I'm new to shadow so apologies if this is something obvious. Does anyone have any idea what's going on here?

Update

So it looks like what's happening is that stream-browserify 2.0.2 requires readable stream ^2.0.2 which npm installs in the nested node_modules folder. Elsewhere readable-stream 3.6.0 is being installed in top level node_modules. Shadow is trying to resolve writer.js against the 3.6.0 version of readable stream instead of the 2.0.2 version.

Confusingly though, stream-browserify isn't a dependency of cipher-base as given in the dependency trace but of node-libs-browser which is itself a dependency of shadow-cljs.

Is it possible that this is a bug in shadow or is it expected behaviour?

Update 2

I've created an example repo that replicates what I'm seeing as simply as I can here.

0

2 Answers 2

1

Did you actually install the shadow-cljs dependency in the project? Does the directory node_modules/shadow-cljs exist?

I see it listed in devDependencies so it should be installed but it might not be if you never actually called npm install in the project or npm is set to production mode which won't install devDependencies. All of this is part of the node-libs-browser package which seems to be missing as well and should have been installed due to being a dependency of shadow-cljs.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Thomas. Can confirm that both shadow-cljs and node-libs-browser are installed and that their folders exist under node_modules.
And that is in the /home/ru/Projects/campfire/node_modules directory? I just tested and the lib compiles fine for me.
Sure, both packages are in the project root node_modules. I just created a repo that replicates the issue on github if that helps.
The problem is on the dependency conflict on the readable-stream dependency. 3.6.0 is installed but stream-browserify wants ^2.0.2. Which you already identified. You can check if there is an updated stream-browserify or if the other libs also work with the older version. Just add a direct dependency for the older version to your project to test.
Ah OK, I assumed it would be alright to have different versions of the same module side by side. I tried forcing version 2.0.2 and everything seems to be working OK. Thanks for the help and for your work on shadow. It's an amazing piece of kit.
0

Based on the link in your first error message, it says to npm install whatever's missing.

If you didn't run npm install, that by itself will install what's in your package.json.

If that's not the issue, then npm i readable-stream may help.

1 Comment

Hey Arron, thanks. I've tried both of those and rebuilt it but I'm getting the same message. I can see readable-stream in the node_modules folder but the file being referenced (writable.js) isn't there. I can't see any file with that name in the readable-stream repo so it looks like an import is being wrongly resolved somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.