babashka / nbb

Scripting in Clojure on Node.js using SCI
Eclipse Public License 1.0
863 stars 52 forks source link

nbb fails with ReferenceError: esm_import$path is not defined #287

Closed gdanov closed 1 year ago

gdanov commented 1 year ago

version

"version": "1.1.149",

platform

osx ventura

problem

~>nbb
file:///Users/gdanov/.nvm/versions/node/v18.12.1/lib/node_modules/nbb/lib/nbb_main.js:41
process.exit(0));$APP.n($APP.I3.g(b))&&($APP.ZB.l($APP.C([["nbb v",$APP.cx()].join("")])),process.exit(0));return $APP.n($APP.n(c)?c:$APP.n(d)?d:$APP.n(a)?a:$APP.n(e)?e:f)?($APP.BW.h($APP.FW,$APP.Eg($APP.MM.g(b))),Promise.resolve($APP.tZ($APP.n(e)?esm_import$path.resolve("script.cljs"):c,b)).then(function(){return($APP.n(c)?$APP.uZ(c):$APP.n(d)?$APP.vZ(d):$APP.n($APP.D3.g(b))?shadow_esm_import("./nbb_nrepl_server.js").then(function(){var g=$APP.D.h($APP.D.h($APP.Pq.g($APP.r($APP.Jq.g($APP.hw()))),
                                                                                                                                                                                                                                                        ^

ReferenceError: esm_import$path is not defined
    at file:///Users/gdanov/.nvm/versions/node/v18.12.1/lib/node_modules/nbb/lib/nbb_main.js:41:249
    at file:///Users/gdanov/.nvm/versions/node/v18.12.1/lib/node_modules/nbb/lib/nbb_main.js:43:283
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v18.12.1

repro

nbb stopped working, not sure why. fresh node re-install does not help.

borkdude commented 1 year ago

do older versions still work for you? how did you install nbb, locally, globally? can you provide a repro repository?

gdanov commented 1 year ago

I just erased everything in the node folder and ran npx i nbb -g then nbb before that tested with npx, same.

borkdude commented 1 year ago

I can reproduce this locally too:

npm install -g nbb@1.1.149

gives this problem, but:

npm install -g nbb@1.1.148

doesn't.

gdanov commented 1 year ago

right. 148 and 147 are good.

borkdude commented 1 year ago

Releasing 1.1.150 now. It seemed this bug is introduced by upgrading shadow-cljs. I tested with 2.20.6 and the bug first starts happening with 2.20.7. cc @thheller

borkdude commented 1 year ago

@thheller If you're interested in reproducing:

borkdude commented 1 year ago

npm install -g nbb@1.1.150 now works for me. Let's leave the issue open until we sorted it out with shadow. I'd be happy to create an issue with shadow-cljs if necessary.

thheller commented 1 year ago

How do I turn on --pseudo-names for the release build? No clue what happens where.

Nevermind. It is passed through in the bb release command.

thheller commented 1 year ago

Found the problem. In 2.20.7 I changed how the ESM import statements are handled, so that JS tools can tree-shake them properly. What I guess I missed is that in this case it moves the code from the nbb-main-impl module to the nbb-main module and calls it there. The code does not account for ESM references moving cross modules, so this fails now.

borkdude commented 1 year ago

@thheller

bb release --pseudo-names

should work. Thanks for looking into it.

thheller commented 1 year ago

Should be fine again in 2.20.13.

borkdude commented 1 year ago

@thheller Thanks!