Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use npm deps in CLJS library #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

madis
Copy link
Owner

@madis madis commented Jun 2, 2022

Looking for a way to configure, build & release a CLJS library that depends on another NPM library so that the user of the CLJS library doesn't have to specify NPM dependencies in package.json but rather would get them automatically

Original question asked in Clojurians Slack https://clojurians.slack.com/archives/C03S1L9DN/p1654078943735149

How to develop/build/release CLJS library that has transitive dependencies on NPM libraries, so that the application consuming the CLJS library could get the NPM dependencies with minimum overhead. Two scenarios:
  - App => CLJS lib => NPM lib
  - App => CLJS lib A => CLJS lib B => NPM lib

This branch (pull request) has made the following changes:

  1. replaced deps.edn with deps.cljs

Currently the build npx shadow-cljs compile test-node fails with

Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate shadow/cljs/devtools/cli__init.class, shadow/cljs/devtools/cli.clj or shadow/cljs/devtools/cli.cljc on classpath.

Which can be gotten around by adding shadow-cljs to either package.json or deps.edn
But then the deps.cljs never seems to be interpreted and as there is no test_trans_dep NPM library (node_modules stays empty), the following error is thrown after compilation when runing node out/node-tests.js

SHADOW import error /home/madis/code/cljs-library-demo/test-lib/.shadow-cljs/builds/test-node/dev/out/cljs-runtime/shadow.js.shim.module$test_trans_dep.js
/home/madis/code/cljs-library-demo/test-lib/out/node-tests.js:67
    throw e;
    ^

Error: Cannot find module 'test_trans_dep'
Require stack:
- /home/madis/code/cljs-library-demo/test-lib/out/node-tests.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at /home/madis/code/cljs-library-demo/test-lib/.shadow-cljs/builds/test-node/dev/out/cljs-runtime/shadow.js.shim.module$test_trans_dep.js:3:40
    at global.SHADOW_IMPORT (/home/madis/code/cljs-library-demo/test-lib/out/node-tests.js:64:44)
    at /home/madis/code/cljs-library-demo/test-lib/out/node-tests.js:2162:1
    at Object.<anonymous> (/home/madis/code/cljs-library-demo/test-lib/out/node-tests.js:2172:3)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/madis/code/cljs-library-demo/test-lib/out/node-tests.js' ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant