Fork me on GitHub
#nbb
<
2022-11-17
>
borkdude10:11:03

Load nbb in Github comments :star-struck: https://twitter.com/borkdude/status/1593183576019070976

👀 1
🎉 1
borkdude12:11:02

And another surprise today, apparently you can run nbb with deno now: https://twitter.com/borkdude/status/1593213424619917314

sparkofreason15:11:12

Has anybody worked out how to import a TypeScript module into a nbb REPL?

borkdude15:11:10

@dave.dixon Can you be more specific?

sparkofreason15:11:58

I'm running nbb via calva. This is very handy for interactive development, but right now I'm building/running the TypeScript app externally and loading output through a file into nbb. It would be really nice if I could change the TypeScript, load that (presumably transpiled to JS) code into nbb, and call it to see the results interactively rather than doing a whole compile/run cycle.

borkdude15:11:03

yes, you can do this, but without some sort of repro, it's hard to be specific on how to do this

borkdude15:11:28

you can do (:require ["./foo.js"]) assuming that TS will spit out some .js file

1
👀 1
sparkofreason15:11:22

Thanks. I'll work on this a bit. Pretty sure the above is possible, and maybe I can call the TypeScript API directly to compile/load from nbb. I'll research it.

sparkofreason16:11:37

How about coming at this from the other direction, and launching a REPL server from the JS end?

borkdude16:11:36

perhaps make an issue for this, I don't think this is currently exposed

1
borkdude20:11:33

@dave.dixon Publishing 1.1.145 now which should have this: https://github.com/babashka/nbb#nrepl-api

borkdude20:11:12

crap, build failure on CI

borkdude21:11:29

retrying a new publish

1
borkdude21:11:24

OK, this worked, version 1.1.146

sparkofreason00:11:31

Thanks. I seem to be stuck in module incompatbility hell, Instead change the require of /Users/dave.dixon/Projects/de_flare/node_modules/nbb/index.mjs to a dynamic import() which is available in all CommonJS modules., so far haven't been able to try this out. I'll see if I can find a workaround.

borkdude06:11:54

Yes, you could do this as a dynamic import in an async function if you’re using cjs

borkdude08:11:31

@dave.dixon Here is how you do that:

async function nREPL() {
  const { loadString } = await import('nbb');
  await loadString(`
  (require '[nbb.nrepl-server :as nrepl])
  (nrepl/start-server! {:port 1337})
`);
}

nREPL();

sparkofreason13:11:04

Thanks, but there's some issue with how we have our TypeScript project set up where it doesn't work. I either need to sneak in a pure JS script that avoids the TS transpiler, or get the right set of TS config options that won't break compilation on the rest of our codebase.

sparkofreason17:11:56

Found a possible workaround here. The core problem seems to be that we use ts-node, and that has issues with ESM imports. But if I make our server startup pure JS, and tell ts-node to not transpile files with the .js extension, it works: ts-node --ignore \.js src/server.js. That also explains the error, which I think occurred because ts-node was "helpfully" converting import to require behind the scenes.