Fork me on GitHub
#nbb
<
2023-11-04
>
Raúl Sánchez Ruiz12:11:45

Hi everyone! I started to use nbb with Deno 😃 ( I like dinosaurs 🦕 😂 ) because I understand that bebo is not than mature that nbb but I have problems to use npm modules if I not use package.json and node_modules folder. What is the better approach to use nbb with deno? Can be use deno compile? The project that I started is a azure pipeline generator

borkdude12:11:40

Hey :) I don't know exactly what your problem is but maybe a repro would help

borkdude12:11:08

Perhaps using something like #squint would work better with deno, not sure

borkdude12:11:53

The "bebo" project doesn't seem to be necessary anymore since nbb now works with deno

Raúl Sánchez Ruiz12:11:53

The problem is only that when I try to require a npm library nbb not found it if I don’t do before npm install library. I try to use a ts file when import nbb and all the npm libraries before loadfile nbb’s method

Raúl Sánchez Ruiz12:11:11

I’ll try to create a repo to show the example

borkdude12:11:56

ah this is maybe because nbb used dynamic import which deno doesn't support that well? thanks, I'll look forward to the repro

Raúl Sánchez Ruiz12:11:11

I don’t know squint, it looks an interesting project 😃. I’m a noob of clojure and all the clojure’s ecosystem but I’ll try to use it in my new proyects for learning it. I like the concept of babashka and nbb because I can use it for a cli development this is the reason because I start my journey with nbb 😃

Raúl Sánchez Ruiz12:11:33

And nbb because I need a template engine and try to use nunjucks. I don’t know if exists something similar that I can use with bb

Raúl Sánchez Ruiz12:11:59

Jejeje I’m really noob in this world sorry if I don’t know something obvious

borkdude12:11:09

can you maybe try

async function foo() {
  import('my-library');
}

await foo(); 
in a .js file in deno? without having my-library inside node_modules / package.json? I think this will fail in deno and this is similar to how nbb behaves. With squint however, it first generates source code and then that is executed by deno, which is more like:
import * as my_lib from 'my-library'

Raúl Sánchez Ruiz12:11:32

Ohhh thanks! I’ll try to use it and I’ll tell to you the result of the testing 😃

😃 1
Raúl Sánchez Ruiz16:11:21

Hi again! I finally found the way to my code works. This is the repo: https://github.com/ulthuan/test_nbb If you execute with deno run -A run_bb.ts don’t work but if you run with the —node-modules-dir flag deno itself create the node_module directory and all works 😃. I hope this example helps to others 😃

borkdude16:11:31

It would be helpful if you could add to the README how to actually run it. I tried a bunch of different things like:

deno run —-node-modules-dir run_bb.ts

borkdude16:11:35

but that doesn't work for me ;)

Raúl Sánchez Ruiz17:11:07

Sorry I suppose that I do something wrong 😑. I updated the repo with a Readme file and config file of deno that help to run the example easily

Raúl Sánchez Ruiz17:11:37

I try again to run my example to detect the errors

Raúl Sánchez Ruiz17:11:08

I updated a little bit the Readme for help to understand better the options and the example I hope that now works when you run it

borkdude18:11:00

@U063PEZMD7Y I'm seeing this now:

$ deno run -A --node-modules-dir --lock run_bb.ts
error: the following required arguments were not provided:
  [SCRIPT_ARG]...

Usage: deno run --allow-all --node-modules-dir[=<node-modules-dir>] --lock [<FILE>] [SCRIPT_ARG]...

For more information, try '--help'.

Raúl Sánchez Ruiz18:11:40

What is your deno version for try to reproduce it?

borkdude18:11:17

It seems the output says that it expects a file after the --lock argument?

Raúl Sánchez Ruiz18:11:21

It’s strange because I try again cleaning cache before just in case

borkdude18:11:38

$ deno --version
deno 1.37.2 (release, aarch64-apple-darwin)
v8 11.8.172.13
typescript 5.2.2

Raúl Sánchez Ruiz18:11:45

Try to run it without extra flags

Raúl Sánchez Ruiz18:11:56

And with the deno.json

Raúl Sánchez Ruiz18:11:11

deno run -A run_bb.ts

borkdude18:11:38

$ deno run -A run_bb.ts
"Hello world!"

Raúl Sánchez Ruiz18:11:41

The configuration file use the lock file and the node_modules directory … it’s the same that the flags but I suppose that don’t work as I expected 😓

Raúl Sánchez Ruiz18:11:25

I’ll try again and fix the documentation with the use of the explicit name of the file in the lock parameter. Thanks for your time! I hope that this example help to more user of deno + nbb 😃

borkdude18:11:14

ok, but I guess this only works because you added import "npm:nunjucks" to the start file right?

Raúl Sánchez Ruiz18:11:51

Another option for that it’s a use of deps.ts file with all the dependencies and cache it before run nbb in the same folder

borkdude18:11:11

you might as well just use npm install?

Raúl Sánchez Ruiz18:11:55

Yes it’s another option of course I try it before and works too

Raúl Sánchez Ruiz18:11:46

I think that a little “wrapper” for use deno with nbb it’s the load of deps.ts it’s a default convention in deno

Raúl Sánchez Ruiz19:11:51

I’ll try a little more because I don’t know all the options that the deno runtime provides but at this moment with my knowledge those are the best options that I know

borkdude19:11:09

cool, perhaps we can document this in $nbb_repo/doc/deno.md or so

Raúl Sánchez Ruiz19:11:23

I’ll glad to write that .md when I finished a little bit more research and we’ll can discuss the content of the file through here or a direct message or after the first push in the PR

Raúl Sánchez Ruiz07:11:22

Hi again! I updated the example repo with the compromise solution that I think that helps more to develop with Deno. The workflow will be like that: change deno.json with new dependencies, run the task update_cache and after that you can use the nbb task to run your code. If you want to distribute your code you can use the nbb_compile task to generate a self contained binary. You’ll need the jq utility to run the update_cache task

👍 1