Skip to content

:target :esm unable to require native Node modules such as "process" #1219

Open
@awwx

Description

@awwx

Here I want to compile ClojureScript to a JavaScript module that will run in Node, and which uses the native Node module "process".

package.json:

{
  "devDependencies": {
    "shadow-cljs": "^2.28.21"
  }
}

shadow-cljs.edn:

{:source-paths ["src"]
 :builds
 {:go
  {:target :esm
   :runtime :node
   :output-dir "js"
   :modules
   {:go {:exports {go run/go}}}}}}

src/run.cljs:

(ns run
  (:require
    ["process" :as node-process]))

(defn go []
  (println "this is run go"))
$ npx shadow-cljs compile go
shadow-cljs - config: /home/andrew/prj/pull-flow/shadow-cljs.edn
[:go] Compiling ...
The required JS dependency "process" is not available, it was required by "run.cljs".

Dependency Trace:
	run.cljs

Searched for npm packages in:
	/home/andrew/prj/pull-flow/node_modules
process is part of the node-libs-browser polyfill package to provide node-native package support
for none-node builds. You should install shadow-cljs in your project to provide that dependency.

	npm install --save-dev shadow-cljs

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

I tried some :js-options :resolve options but didn't find one that seemed to make a difference.

Is there a way to say, "Believe me, 'process' is there, just go ahead and use it"?

Not particularly urgent because I can pass "process" from JavaScript to my ClojureScript code, but was wondering if there was a way to do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions