Issue with commiting res.js files without CI build step

Following the recommendations on this page Interop with JS Build Systems

We also recommend that you initially check in those ReScript-generated JS files, as this workflow means:

  • You can introduce ReScript silently into your codebase without disturbing existing infra.

I tried taking this approach in my project and commited my generated rescript files with the .res.js extension, but ran into an issue because @rescript/core is published with just .mjs.

Running a build locally remakes the files as .res.js inside of node_modules, but when I push my code to CI those don’t exist, and since the file ext is hardcoded in the output src this leads to a “module not found”:

import * as Core__Option from "@rescript/core/src/Core__Option.res.js";

I can update my config to use .mjs, but now I’ll run into an issue where rescript-react is using .bs.js

For the no-CI approach to work, I think the rescript compiler should use the extension in each package’s rescript.json

1 Like

That advice is a bit old now, although it might become viable again once core is pulled into the compiler rather than a dependency.

Personally, I completely disagree with committing generated code - of any form - to source control. And that also applies for publishing to NPM.

Libraries can’t be expected to publish every flavour of modules ReScript can generate, and in fact if your dependency was last compiled with an old version you may find incompatibilities with the generated code (for example the swap from curried to uncurried by default in v11).

It’s much safer, and usually not very difficult, to run rescript during the CI process.

4 Likes