so I’m revisiting this hellhole again trying to figure things out. because of node.js and esm, it’s turned into an absolute mess. with rescript on top of that, it’s even more confusing.
first off, if I provied a rescript library, it seems to be built with rescript using the suffix from the client rescript.json.
that means I can set type: module in the main repo and then use suffix .res.js, for example.
however, it will use the library’s package.json, which won’t have type: module set in it, which makes everything not run (early runtime failure)
alright, so I can set the suffix to .res.mjs and not have to care about setting type: module, and the library will be built with .res.mjs too. but now the rescript core library stops working:
because it doesn’t provide any .res.mjs files, only .mjs or .js it seems? so now I have to set my suffix to .mjs for it to work.
I mean, bottom line - why do I even get a pick? what am I misunderstanding? optimally I want to use .res.js and type module because I dislike using mjs and I want to have .res for clarity, but then nothing works lol
I did - but only .mjs works. Maybe I can come up with a small repro for this, but it just isn’t building. It seems to have to do with rescript libraries
I have to admit I’ve seen problems like this in my own code and I’m not quite sure how I fixed it.
I did accept however that suffix: “bs.mjs” causes the least problem. The .mjs because node doesn’t need some config file to figure out how to run it, and .bs. because otherwise you might overwrite some javascript code you are binding too (yes I’ve done that)
I’ve had suffix problems but with only the Option core module
I’ve had problems because using vite will require type:“module” be set, but rescript doesn’t require it, so when you are working on the backend side you think nothing is wrong until you start up the front end.
it doesnt help that rescript init creates a config with “suffix”: “.bs.js”
and various bundlers like vite and rescript-starter-app will transpile things behind the scenes so you might not be actually using ES6 so you might be sheltered from these problems until you crank up node for something.
and the getting started docs tell you to do one thing, then the user discovers rescript init which creates a different config, and then the rescript react docs don’t even tell you how to get started. rust is more welcoming than rescript and that’s saying something.
if I knew what I was doing with rescript and could help I’d focus on two areas of improvement, get rescript init to be friendly to new and existing projects, remove the setup docs and tell the user to use rescript init, and get vite to add a rescript template that shows up like this
❯ npm create vite@latest
Need to install the following packages:
create-vite@5.1.0
Ok to proceed? (y) y
✔ Project name: … vite-project
? Select a framework: › - Use arrow-keys. Return to submit.
❯ Vanilla
Vue
React
Preact
Lit
Svelte
Solid
Qwik
Rescript-React <----------
Others