i’m new to rescript.
I’m trying to do a simple command line project where i need node libs.
I have seen that there is a package implementing node bindings which is called
I created a simple project with create rescript.
I installed rescript-nodejs in my project with npm.
I added rescript-nodejs to the
rescript.json of my project.
When i try to use
Fs.readfile in my code, the compiler complains that the module Fs can’t be found.
The compiler suggest to me to add it to bsconfig.json (shouldn’t it be rescript.json in v11 ? Slightly confusing), but it is already in the bs-dependencies array of my rescript.json.
Did i forgot something ?
The Node bindings are namespaced under NodeJs by default, so you’d need to use NodeJs.Fs by default. Looks like the Node bindings docs should probably mention this.
You could also do a
open NodeJs in your file and you’ll have access to Fs directly.
And, if you want a more integrated experience still, you can open the NodeJs globally in all files automatically by adding this to your config file:
"bsc-flags" : ["-open NodeJs"] .
I prefer the last alternative when working with Node or Bun. It’s a pretty nice experience where everything Node is instantly available.
Thank you for your help.
Reading the source code of the module, i can’t find where it’s defining that the export will be under the name
Where should this be set ?
I believe it is in
I thought all libraries operated this way to be good namespace citizens, so I didn’t even consider adding it to the readme (most of which I inherited from the project I forked).
I will admit that the readme code snippets are misleading, though, and despite the project having working examples they’re also not listed in the readme.
I guess every library might be somebody’s first library and I need to do better.
My message definitely wasn’t intended to say you weren’t doing a good job, the lib is great! It was just a note.
I opened a PR to add
open NodeJs to the readme examples as well. That should make things as clear as possible I guess.
That’s ok, I am my harshest critic
Thanks for the PR!