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.