Fork me on GitHub
#shadow-cljs
<
2023-06-29
>
Jakub Holý (HolyJak)14:06:14

Hello! At random, I get a parse exception for a 3rd party JS file. The weird thing it only happens sometimes. It looks like this:

Failed to inspect file
  /Users/me/Projects/external/fulcro-community/fulcro-cookbok/node_modules/highlight.js/lib/languages/isbl.js

Errors encountered while trying to parse file
  /Users/me/Projects/external/fulcro-community/fulcro-cookbok/node_modules/highlight.js/lib/languages/isbl.js
  {:line 1, :column 1, :message "The file could not be parsed as JavaScript."}

RuntimeException: Exception parsing "/Users/me/Projects/external/fulcro-community/fulcro-cookbok/node_modules/highlight.js/lib/languages/isbl.js"
	com.google.javascript.jscomp.parsing.ParserRunner.parse (ParserRunner.java:148)
	com.google.javascript.jscomp.JsAst.parse (JsAst.java:157)
	com.google.javascript.jscomp.JsAst.getAstRoot (JsAst.java:63)
	shadow.build.closure.JsInspector.getFileInfo (JsInspector.java:185)
	shadow.build.closure.JsInspector.getFileInfoMap (JsInspector.java:199)
	shadow.build.npm/get-file-info*/fn--12380 (npm.clj:371)
Any tips how to prevent it? 🙏

Hendrik15:06:09

Do you use advanced compilation?

Boldizsár Rácz17:06:43

Hello! I have a project using https://github.com/day8/re-frame-10x, In order to get it work with shadow cljs I added the highlight.js to the package.json. It worked ok until the latest 2.24.0 shadow update. Now, I have this error when I try to start watching the cljs build with shadow:

require "./lib/languages/clojure" for package "SOME_PATH/node_modules/highlight.js" not exported
{:rel-require "./lib/languages/clojure", :package-dir #object[java.io.File 0x4a2ec8c1 "SOME_PATH/node_modules/highlight.js"], :exports {"." {"require" "./lib/index.js", "import" "./es/index.js"}, "./package.json" "./package.json", "./lib/common" {"require" "./lib/common.js", "import" "./es/common.js"}, "./lib/core" {"require" "./lib/core.js", "import" "./es/core.js"}, "./lib/languages/*" {"require" "./lib/languages/*.js", "import" "./es/languages/*.js"}, "./scss/*" "./scss/*", "./styles/*" "./styles/*", "./types/*" "./types/*"}}
ExceptionInfo: require "./lib/languages/clojure" for package "SOME_PATH/node_modules/highlight.js" not exported
        shadow.build.npm/find-resource-from-exports/try-match--48154 (npm.clj:682)
        shadow.build.npm/find-resource-from-exports (npm.clj:716)
        shadow.build.npm/find-resource-from-exports (npm.clj:653)
        shadow.build.npm/find-resource-in-package (npm.clj:747)
       ...
I investigated it a bit further, and found out that it's related to the addition of basic support for package.json exports. I guess something is wrong with the wildcard in the exports:
"./lib/languages/*" {"require" "./lib/languages/*.js", "import" "./es/languages/*.js"}
should probably match with the require
"./lib/languages/clojure"
Right? I added now to my build in the shadow-cljs.edn this entry:
:js-options {:ignore-exports true}
Is this the right thing to do in that case? Thank you.