Getting a new error when trying to build for release:
--- externs.shadow.js:17
Parse error. 'identifier' expected
Error while executing task: -compile
externs.shadow.js shows
/** @const {ShadowJS} */ var ArrayBuffer;
/** @const {ShadowJS} */ var Float64Array;
/** @const {ShadowJS} */ var JSJodaLocale;
/** @const {ShadowJS} */ var Uint32Array;
/** @const {ShadowJS} */ var Uint8Array;
/** @const {ShadowJS} */ var clearInterval;
/** @const {ShadowJS} */ var clearTimeout;
/** @const {ShadowJS} */ var decodeURIComponent;
/** @const {ShadowJS} */ var history;
/** @const {ShadowJS} */ var localStorage;
/** @const {ShadowJS} */ var location;
/** @const {ShadowJS} */ var module;
/** @const {ShadowJS} */ var navigator;
/** @const {ShadowJS} */ var sessionStorage;
/** @const {ShadowJS} */ var setDarkMode;
/** @const {ShadowJS} */ var setInterval;
/** @const {ShadowJS} */ var typeof;
ShadowJS.prototype.$$typeof;
ShadowJS.prototype.$_pfocustrap_firsthiddenfocusableelement;
ShadowJS.prototype.$_pfocustrap_lasthiddenfocusableelement;
ShadowJS.prototype.$attrs;
ShadowJS.prototype.A;
;
(abbreviated) .. any clues? watching build seems fineonly thing that looks suspicious to me is /** @const {ShadowJS} */ var typeof;
guessing for some reason it collected this as an extern it needs to generate. dunno how though.
Hmmm.. is this a ‘figure out which node package is screwing me up’ sort of deal?
I wonder where it is coming from though. since the externs listed in that file are usually collected from CLJS files using JS, not the JS itself?
does any of your CLJS code contain a reference to typeof?
A good question, let me check
nothing in my code, but when I look at all cljs code in intellij, I get some results like:
(defn type-of [x]
(js* "typeof ~{}" x))
;;;;;;;;;;;; This file autogenerated from src/cljx/schema/utils.cljx
that wouldn't generate externs
try this at the CLJ REPL
(->> (shadow/compile* :your-build)
(:compiler-env)
(:cljs.analyzer/namespaces)
(vals)
(filter (fn [{:shadow/keys [js-access-globals] :as x}]
(contains? js-access-globals "typeof"))))that should have one hit
Execution error (ArityException) at shadow.user/eval84850 (REPL:1). Wrong number of args (1) passed to: shadow.cljs.devtools.api/compile*
just change :your-build to whatever your build if is of course
oh right add a second {} arg there
(->> (shadow/compile* :pnx {}) (:compiler-env) (:cljs.analyzer/namespaces) (vals) (filter (fn [{:shadow/keys [js-access-globals] :as x}] (contains? js-access-globals “typeof”)))) [null] Compiling ... Execution error (AssertionError) at shadow.build/configure (build.clj:314). Assert failed: (map? config)
(->> (shadow/compile* (shadow/get-config! :pnx) {})
(:compiler-env)
(:cljs.analyzer/namespaces)
(vals)
(filter (fn [{:shadow/keys [js-access-globals] :as x}]
(contains? js-access-globals "typeof"))))sorry I don't know my own APIs 😛
(->> (shadow/compile* (shadow/get-build-config :pnx) {})
(:compiler-env)
(:cljs.analyzer/namespaces)
(vals)
(filter (fn [{:shadow/keys [js-access-globals] :as x}]
(contains? js-access-globals "typeof"))))that one
I can’t say I know them any better 😉
… it built id just fine, no hits
:builds {:pnx {:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:js-options {:minimize-require false}
:module-hash-names true
:modules {:pnx-web {:init-fn pnx-web.core/init}}
:devtools {:preloads [day8.re-frame-10x.preload]}
:dev {:compiler-options
{:optimizations :none
:closure-defines {re-frame.trace.trace-enabled? true
day8.re-frame.tracing.trace-enabled? true}}}
:release {:output-dir "dist/public/js/compiled"
:build-options {:ns-aliases {day8.re-frame.tracing day8.re-frame.tracing-stubs}}}}that’s the build config in case there’s something screwy with it
maybe just try deleting the .shadow-cljs/builds/pnx/release dir. maybe some bad cache for some reason
that looks fine
I mean it could be possible that its related to the :release tracing switch and thus not showing up for compile*
but the trick above won't work for release* if that doesn't build
I mean you can set :js-options {:generate-externs false} in the config and see if that fixes it
yeah same issue
but it may then lack some externs and cause other issues
sure
gosh, same thing.
ah right no. that just turns off externs from JS files, not CLJS files
so yeah the only source this could be coming from technically is the CLJS source using js/typeof.foo
otherwise I really do not understand where this may be coming from
Yeah me neither
ShadowJS.prototype.$$typeof; these things are possibly collected from npm JS sources
/** @const {ShadowJS} */ var typeof; but this is not
aha ok
they normally only come from CLJS code using js/anything
yeah there are heaps of them from the materialdesignicons npm module
do you have any simplified externs? https://shadow-cljs.github.io/docs/UsersGuide.html#_simplified_externs
I mean global:typeof would explain it too 😛
no simplified externs
> yeah there are heaps of them from the materialdesignicons npm module
what does that mean? there aren't and js/anything references in npm code
that is the code where the /** @const {ShadowJS} */ things come from. thus it not showing up for yours is weird
ShadowJS.prototype.mdiArrowRightCircleOutline;
thats the different kind and not global
ah yeah, right
only the top 17 or so are the global ones from the snipped
I’ve searched for typeof in the whole repo and its only present on js side
only other thing I can think of is going into the CLJ repl
then (in-ns 'shaodw.build.closure)
then just redefining the function generating this stuff
(defn extern-globals-from-cljs [state]
(->> (:build-sources state)
(map #(get-in state [:sources %]))
(filter #(= :cljs (:type %)))
(map (fn [{:keys [ns file] :as src}]
;; we know those don't need externs
(when (not= ns 'cljs.core)
(let [{:shadow/keys [js-access-global]}
(get-in state [:compiler-env :cljs.analyzer/namespaces ns])]
(prn [:ext ns js-access-global])
js-access-global
))))
(reduce set/union #{})))then just doing a release build, which should then print all the extern properties it collected before the build fails
(just added the prn there, might be easier if that already does the "typeof" check and only printing that)
[:ext pnx.data.types #{“typeof”}]
that looks like a problem!
aha, it alluded me because its a cljc file
:cljs [:fn #(= (js/typeof % "bigint"))])
aha. hmm that is totally legit
guess that just needs to be added to the filter so it doesn't try to turn it into externs
let me lookup one other thing and then I can make a new release to fix this
awesome, thanks
I just pushed the 3.2.1 version with a fix for this
Gosh thats fast! thanks!
Hello ! I've got an issue with a package that is ESM only, obviously I can't import it from cjs code
[minisite-publish] error: Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/react-markdown/index.js from /var/task/dist/minisite-ssr.js not supported.
Instead change the require of index.js in /var/task/dist/minisite-ssr.js to a dynamic import() which is available in all CommonJS modules.
at /opt/rust/nodejs.js:2:13528
at (/opt/rust/nodejs.js:2:13906)
at Le.e.<computed>.De._load (/opt/rust/nodejs.js:2:13498)
at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
code: 'ERR_REQUIRE_ESM'
}
So I tried to use a dynamic import and use :target esm instead but now some browser code got included in the build
ReferenceError: document is not defined
at shadow$provide.<computed> (file:///var/task/dist/minisite-ssr/main.mjs:122:314)
at lh (file:///var/task/dist/minisite-ssr/main.mjs:680:472)
at shadow$provide.<computed> (file:///var/task/dist/minisite-ssr/main.mjs:148:289)
at lh (file:///var/task/dist/minisite-ssr/main.mjs:680:472)
at shadow$provide.<computed> (file:///var/task/dist/minisite-ssr/main.mjs:281:46)
at lh (file:///var/task/dist/minisite-ssr/main.mjs:680:472)
at shadow$provide.<computed> (file:///var/task/dist/minisite-ssr/main.mjs:303:81)
at lh (file:///var/task/dist/minisite-ssr/main.mjs:680:472)
at shadow$provide.<computed> (file:///var/task/dist/minisite-ssr/main.mjs:304:175)
at lh (file:///var/task/dist/minisite-ssr/main.mjs:680:472)
Any ideas how I could solve this? Can spin-up a github repo if needed, thanks !It works as long as libs don’t use top level await
:target :esm defaults to assuming a browser runtime. if not set :runtime :node in the build config
in my experience it is easier to just go with ESM if any ESM node packages are involved
it may work for a number of reasons, e.g. different versions of certain packages?
Great thanks, I switched to a cJS equivalent library but I will try : runtime :node
Again thanks for your amazing work on shadow-cljs, it's a beautiful piece of software
it worked because nowadays modern Node.js allow requiring ESM modules from cJS but that feature is not guaranteed everywhere somehow (might be behind a feature flag)
oh really? didn't know that. that should solve some headaches
Something really strange is that this happens only on Vercel (prod PaaS provider) not on my laptop locally, weird
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = PropositionCaseStudy;
var _react = _interopRequireDefault(require("react"));
var _reactMarkdown = _interopRequireDefault(require("react-markdown"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
That's my compiled file with babel, the require("react-markdown") should fail here since it's CJS calling an ESM package but it's working great on my laptop. Is that magic? 😅Ok the reason it works on my local machine is that my Node version allows require of ESM modules but the one provided by Vercel does not
I might simply drop using Vercel for my backend but curious to have your take here