Load nbb in Github comments π€© https://twitter.com/borkdude/status/1593183576019070976
And another surprise today, apparently you can run nbb with deno now: https://twitter.com/borkdude/status/1593213424619917314
Has anybody worked out how to import a TypeScript module into a nbb REPL?
@dave.dixon Can you be more specific?
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.
yes, you can do this, but without some sort of repro, it's hard to be specific on how to do this
you can do (:require ["./foo.js"]) assuming that TS will spit out some .js file
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.
aha!
@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();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.
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.
How about coming at this from the other direction, and launching a REPL server from the JS end?
perhaps make an issue for this, I don't think this is currently exposed
Ah there an issue for it here: https://github.com/babashka/nbb/issues/132
@dave.dixon Publishing 1.1.145 now which should have this: https://github.com/babashka/nbb#nrepl-api
crap, build failure on CI
retrying a new publish
OK, this worked, version 1.1.146
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.
Yes, you could do this as a dynamic import in an async function if youβre using cjs