Share your thoughts in the 2021 Clojure Community Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
I'm trying to use a native NPM module in my CLJS code (in this case, [date-fns|https://github.com/date-fns/date-fns]), and the initial time I try to watch, it works, however on successive watches, it fails with the following error in my console:


base.js:1357 Uncaught Error: Undefined nameToPath for date_fns
    at visitNode (base.js:1357)
    at Object.goog.writeScripts_ (base.js:1369)
    at Object.goog.require (base.js:706)
    at index.html:8


To reproduce, I've created a build script as such:


(require '[cljs.build.api :as b])

(b/watch "src"
  {:main 'npm.core
   :output-to "out/npm.js"
   :output-dir "out"
   :npm-deps {:date-fns "1.29.0"}})


as well as a minimal test file:


(ns npm.core
  (:require [date-fns :as dfn]))

(def now (js/Date.))
(.write js/document "Today is " (dfn/format now "dddd"))


I'm also testing with a local `package.json` file rather than using `install_deps true` - my `package.json` (generated by CLJS) looks like this:


{
  "dependencies": {
    "@cljs-oss/module-deps": "^1.1.1",
    "date-fns": "^1.29.0"
  }
}


When I run:


npm install
java -cp ../clojurescript/target/cljs.jar:src clojure.main watch.clj


everything works fine, however if I CTRL+C and run the same exact command again, I get the error outlined above.

However, if (and only if) I delete the `out` directory and run the command a third time, it works again.

Please let me know if you need any other details.

5 Answers

0 votes
by

Comment made by: koz

Sorry, seemed to mess up on the title and can't seem to edit. The title should be "Re-running watch on CLJS source using native modules results in JS error"

0 votes
by

Comment made by: koz

Additional environment info:

npm -v 5.5.1
node -v v8.4.0

0 votes
by

Comment made by: andyparsons

Noticed that this was switched to priority 4, but this issue is preventing us from using npm dependencies entirely. What does the lower priority reflect?

0 votes
by

Comment made by: mfikes

I can't repro. After hitting Ctrl+C and re-running, I get:

$ java -cp cljs.jar:src clojure.main watch.clj Building ... ... done. Elapsed 3.674686404 seconds Watching paths: /Users/mfikes/Desktop/test-cljs-2440/src

This is with the shipping 1.9.908 {{cljs.jar}} and with Node v9.11.1 and npm 5.6.0.

I've also confirmed that not reproducible with the 1.10.238 JAR.

I also built the 1.9.968 JAR using commit {{ebdaf6c06c1112a67ba5a12498801c6d858e5a0a}} and failed to repro.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2440 (reported by alex+import)
...