Using turbo (turborepo) with ReScript and caching node_modules/**/*

Is anyone successfully using turborepo in their ReScript projects?

I have detailed the issue here:

But in a nutshell, with this config:

{
  "extends": ["//"],
  "pipeline": {
    "build": {
      "outputs": [
        "lib/bs/**/*",
        "src/__generated__/**/*",
        "src/**/*.bs.js",
        "node_modules/**/*.bs.js"
      ],
      "inputs": [
        "src/**/*",
        "node_modules/**/*.{res,ml,mli,atd}",
        "bsconfig.json",
        "relay.config.js"
      ]
    }
}

Turbo does not correctly re-generate node_modules/**/*.bs.js files.

We just ignore inputs and outputs for rescript compiler

Apologies for reviving an old post, but this discussion seems highly relevant to my issue, and I thought it would be better to continue here rather than creating a new thread.

We recently converted our project to a monorepo using Turborepo, and we’re running into an issue with the ReScript package. This package is being used by several TypeScript packages in the monorepo, and we can’t seem to cache its build properly.

Here’s the main problem:

  • Turborepo doesn’t cache builds for dependencies located in node_modules (as pointed out by @KidkArolis).
  • Since the ReScript package can’t be cache it always compiles, any package depending on it has to be rebuilt every time, even if nothing has changed.
  • This results in unnecessary rebuilds for every package that uses the ReScript package, slowing down our workflow.

Seems like a real problem for some project to create some rescript package inside monorepos using turbo if all packages depending on one rescript package has to be rebuild

Has anyone found a workaround or solution to cache the ReScript package build more efficiently in this setup?

Have you looked into Rewatch?
GitHub - rescript-lang/rewatch: Rewatch is an alternative build system for the Rescript Compiler.

Yes, we don’t use it (some hacks on our side that aren’t well supported and don’t have time to address for now), but I think it will also build dependencies (like webapi …) inside node_modules, so if you use the package inside another javascript package you can’t rely on the turbo cache

We use pnpm + turborepo + rewatch in a repo with apps/ and packages/ directories.

Rewatch build gets ran at the root as part of "prepare" and we exclude *.res files from our inputs:

      "build": {
         "dependsOn": ["^build"],
         "outputs": ["dist/**"],
         "inputs": ["$TURBO_DEFAULT$", "!src/**/*.res"]
      },

This seems to work pretty okay for us, development is always pnpm dev:res and turbo start -F

4 Likes