shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
wombawomba 2021-04-10T10:38:56.043100Z

I ran into a wierd situation where I was using one Node libray that was working well with shadow-cljs (https://github.com/react-syntax-highlighter/react-syntax-highlighter), and then added another library that works well with shadow-cljs (https://github.com/otakustay/react-diff-view – has no dependencies), and this caused shadow-cljs to be unable to import the former library. Oddly enough, removing the latter dependency (via yarn remove) does not seem to help. I've also tried restarting shadow-cljs and removing all build files. The import that fails is [react-syntax-highlighter :refer [Prism]], the error is, the line that fails in the generated code is Object.defineProperty(exports,"Prism",{enumerable:!0,get:function(){return _prism.default}}), and the error (that happens in the browser – everything compiles without error) is:

TypeError: Cannot read property 'default' of undefined
    at Object.get [as Prism] (<url-for-cljs-runtime-dir>/module$node_modules$react_syntax_highlighter$dist$cjs$index.js:2:442)
Any idea what could be going on here? How can I debug this further?

wombawomba 2021-04-10T10:44:43.044600Z

...actually, one strange thing that I just found is that cljs-runtime/module$node_modules$react_syntax_highlighter$dist$cjs$prism.js.map contains var _prism = _interopRequireDefault(require(\"./styles/prism/prism\")); , but there's no corresponding var _prism line in cljs-runtime/module$node_modules$react_syntax_highlighter$dist$cjs$prism.js

wombawomba 2021-04-10T10:46:26.045Z

FWIW here's prism.js:

shadow$provide.module$node_modules$react_syntax_highlighter$dist$cjs$prism=function(global,require,module,exports){var _interopRequireDefault=require("module$node_modules$$babel$runtime$helpers$interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0});exports.default=void 0;global=_interopRequireDefault(require("module$node_modules$react_syntax_highlighter$dist$cjs$highlight"));module=_interopRequireDefault(require("module$node_modules$react_syntax_highlighter$dist$cjs$styles$prism$prism"));
var _refractor=_interopRequireDefault(require("module$node_modules$refractor$index"));require=_interopRequireDefault(require("module$node_modules$react_syntax_highlighter$dist$cjs$languages$prism$supported_languages"));global=(0,global.default)(_refractor.default,module.default);global.supportedLanguages=require.default;exports.default=global}

wombawomba 2021-04-10T10:46:55.045200Z

and here's prism.js.map:

{
"version":3,
"file":"module$node_modules$react_syntax_highlighter$dist$cjs$prism.js",
"lineCount":2,
"mappings":"AAAAA,cAAA,CAAe,2DAAf,CAAgF,QAAQ,CAACC,MAAD,CAAQC,OAAR,CAAgBC,MAAhB,CAAuBC,OAAvB,CAAgC,CAGxH,IAAIC,uBAAyBH,OAAA,CAAQ,kEAAR,CAE7BI,OAAA,CAAOC,cAAP,CAAsBH,OAAtB,CAA+B,YAA/B,CAA6C,CAC3CI,MAAO,CAAA,CADoC,CAA7C,CAGAJ,QAAA,CAAQK,OAAR,CAAkB,IAAK,EAEnBC,OAAAA,CAAaL,sBAAA,CAAuBH,OAAA,CAAQ,iEAAR,CAAvB,CAEbS,OAAAA,CAASN,sBAAA,CAAuBH,OAAA,CAAQ,0EAAR,CAAvB,CAEb;IAAIU,WAAaP,sBAAA,CAAuBH,OAAA,CAAQ,qCAAR,CAAvB,CAEbW,QAAAA,CAAsBR,sBAAA,CAAuBH,OAAA,CAAQ,2FAAR,CAAvB,CAEtBY,OAAAA,CAAc,CAAC,CAAA,CAAGJ,MAAH,CAAcD,OAAf,EAAwBG,UAAxB,CAAmCH,OAAnC,CAA4CE,MAA5C,CAAmDF,OAAnD,CAClBK,OAAA,CAAYC,kBAAZ,CAAiCF,OAAjC,CAAqDJ,OAErDL,QAAA,CAAQK,OAAR,CADeK,MApByG;",
"sources":["node_modules/react-syntax-highlighter/dist/cjs/prism.js"],
"sourcesContent":["shadow$provide[\"module$node_modules$react_syntax_highlighter$dist$cjs$prism\"] = function(global,require,module,exports) {\n\"use strict\";\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\nexports.default = void 0;\n\nvar _highlight = _interopRequireDefault(require(\"./highlight\"));\n\nvar _prism = _interopRequireDefault(require(\"./styles/prism/prism\"));\n\nvar _refractor = _interopRequireDefault(require(\"refractor\"));\n\nvar _supportedLanguages = _interopRequireDefault(require(\"./languages/prism/supported-languages\"));\n\nvar highlighter = (0, _highlight.default)(_refractor.default, _prism.default);\nhighlighter.supportedLanguages = _supportedLanguages.default;\nvar _default = highlighter;\nexports.default = _default;\n};"],
"names":["shadow$provide","global","require","module","exports","_interopRequireDefault","Object","defineProperty","value","default","_highlight","_prism","_refractor","_supportedLanguages","highlighter","supportedLanguages"]
}

wombawomba 2021-04-10T10:56:25.045400Z

...it looks to me like shadow-cljs is leaving out a few lines of prism.js. Could this be a bug, or is there something I should be doing to make sure that these lines get included?

wombawomba 2021-04-10T11:13:52.045800Z

just saw that there's another error that happens prior to this:

TypeError: $jscomp.inherits is not a function

wombawomba 2021-04-10T11:15:49.046100Z

I followed the instructions at https://stackoverflow.com/questions/64169633/clojurescript-typeerror-jscomp-inherits-is-not-a-function, and now it works!

wombawomba 2021-04-10T11:16:21.046500Z

Thanks thheller for making a great tool btw :)

2021-04-10T13:41:00.047800Z

I am trying.

Joseph Rollins 2021-04-10T16:14:29.052700Z

I'm trying to manage building functions for firebase alongside my clientside app. I'm currently using 2 builds to achieve this with the functions being built into the expected functions/index.js file. Unfortunately this requires duplicating my dependencies since firebase expects a functions/package.json file listing all deps and I also have to include those deps in the root package.json for shadow. Is there any way around this duplication. I don't see any support in shadow for specifying a different package.json for a particular build. Maybe there is another solution I'm missing?

thheller 2021-04-10T16:41:51.054Z

@rollins.joseph in your functions build you can configure :js-options {:js-packages-dirs ["functions/node_nodules"]} then it'll take the packages installed there instead of the default <project>/node_modules

thheller 2021-04-10T16:43:28.055700Z

@admin055 I still don't know enough about inertia. I repeat that you should follow the code-splitting guide I posted yesterday. That will give you everything you need I think. It would be the same for esm basically, the dynamic import doesn't do anything magic for you.

👍 1
Joseph Rollins 2021-04-10T16:44:27.056Z

@thheller thanks, i'll give that a try

thheller 2021-04-10T16:44:34.056100Z

when stuff works one way but then breaks when you add another package that is almost always caused by a version conflict on a common dependency

thheller 2021-04-10T16:45:21.056500Z

lib A requiring v1 and lib B requiring v2 of some dependency and that often causes trouble