Fork me on GitHub
#nbb
<
2022-11-08
>
Adam Kalisz15:11:30

How can I rewrite this import { datetime, RRule, RRuleSet, rrulestr } from 'rrule' in nbb (https://github.com/jakubroztocil/rrule)? I am interested in the datetime as I can't seem to get it work using e.g (require '["rrule$default" :as rrule :refer [datetime]])

borkdude15:11:28

probably you need to remove $default

👍 1
borkdude15:11:54

in doubt you can do this in a Node.js repl:

x = await import("rrule")

borkdude15:11:59

and then inspect what is inside of x

borkdude15:11:15

I only see x.default and x.rrule

👍 1
Adam Kalisz15:11:23

I am a bit lost here. Without the default, e.g. (rrule.RRule.parseString "DTSTART:20120201T093000Z\nRRULE:FREQ=WEEKLY") stops working with the error "TypeError: Cannot use 'in' operator to search for 'parseString' in undefined".

borkdude15:11:29

and x.rrule is undefined

borkdude15:11:03

so first try this approach in a Node REPL, the structure should be similar in nbb. Use node 17.8.0 for await + import in the repl

borkdude15:11:35

When I try this in a foo.mjs file, I get an error:

import { datetime, RRule, RRuleSet, rrulestr } from 'rrule'

borkdude15:11:44

$ node foo.mjs
file:///private/tmp/rrule/foo.mjs:1
import { datetime, RRule, RRuleSet, rrulestr } from 'rrule'
                   ^^^^^
SyntaxError: Named export 'RRule' not found. The requested module 'rrule' is a CommonJS module, which may not support all module.exports as named exports.

borkdude15:11:49

@adam.kalisz This is a but f** up, but it works:

$ nbb -e "(require '[\"rrule$default\" :as rrule]) rrule.default.RRule"
#object[t]

Adam Kalisz15:11:14

Good tips. Thank you! I still don't understand much but some good pointers here! I will try my best to dig deeper.

Adam Kalisz15:11:44

Got this:

(require '["rrule$default" :as rrule])
(def event-spec (.fromString rrule.RRule. "DTSTART:20120201T093000Z\nRRULE:FREQ=WEEKLY"))
(.between event-spec (js/Date. (.UTC js/Date 2012 2 31)) (js/Date. (.UTC js/Date 2013 01 02)))
That works!

borkdude15:11:45

I think in that case (require '["rrule$default" :as rrule :refer [RRule]]) should have worked, so this may be a bug in nbb as well. Feel free to post an issue

borkdude15:11:05

maybe the combination as + refer isn't that common that I've never hit this yet

Adam Kalisz16:11:23

I think I was ever only writing about :refer [datetime] which we have clarified is probably a different issue. So I am not sure what to file as I think the problem is not in nbb but in my understanding of the subtle interactions in and with JS/ TS libraries. 🙂

borkdude16:11:03

I mean, if (require '["rrule$default" :as rrule]) + rrule.RRule works then (require '["rrule$default" :as rrule :refer [RRule]])` should also work