How to upgrade to v12 in monorepo?

I have a monorepo with two apps and one shared lib:

node_modules/
web/
    - lib/
    - apps/
        - app1/
        - app2/

Both apps and the lib have own rescript.json. Both apps have web/lib as a dependency.

How to upgrade this setup to v12?

P.S. I use npm (with workspaces) as a package manager.

As a fallback, use rescript legacy.

Otherwise, create a root-level rescript.json and list your three projects as dependencies. Ensure that the name fields in each package.json match the corresponding names in rescript.json.

Run rescript --verbose to output the detected project contexts. When configured correctly, running this command from the repository root will display the monorepo structure.

I also replied on GitHub with additional details.

1 Like

hey @nojaf thanks for the pointers!

After I added all monorepo packages as deps and set sources as an empty array, it resolved the deps. But I bumped into the issue with @rescript/react: it still uses old pipe (|>) syntax which is dropped in v12?

Yes, could you try bumping @rescript/react to 0.14.0

Ah, yeah, I thought I’m already on 0.14, but I’m on 0.13. Trying it, thanks!

Alright, I’m arrived at Pervasives stage :sweat_smile:

 The module or file Pervasives can't be found.
  - If it's a third-party dependency:
    - Did you add it to the "dependencies" or "dev-dependencies" in rescript.json?
  - Did you include the file's directory to the "sources" in rescript.json?

Wonderful, that would indicate that @rescript/runtime is not found.
Could you describe in which folder it is installed?
Are you running rescript build from your repo root?

Actually, I didn’t have @rescript/runtime installed. After I installed it and added to the dependencies section of lib package, the Pervasives is gone, but I’m getting this:

[1/7] 📦 Building package tree...ERROR:
We could not build package tree  '@rescript/runtime', at path '/Users/Alex/Dev/psc'. Error: No such file or directory (os error 2)

FWIW @rescript/runtime doesn’t have rescript.json, only package.json.


I run rescript build from the package directory.
If I run rescript build from the root, it succeeds, but doesn’t build anything because the sources is empty.

From the root, it should have build your dependencies. It is normal that your root rescript.json doesn’t have any sources. It makes sense to me that building from the package level won’t work, that is something we still need to fix.

Can you try one last rescript clean and rescript build from the root.
I would expect that at least to work.

From the root, it exits with 0:

❯ npm exec -- rescript clean
Cleaning... 0 files.

❯ npm exec -- rescript build
>>>> Start compiling
Dependency Finished
>>>> Finish compiling 7 mseconds

But when I try to build the package from the package directory:

❯ npm exec -- rescript build 
[1/7] 📦 Building package tree...ERROR:
We could not build package tree  '@rescript/runtime', at path '/Users/Alex/Dev/psc'. Error: No such file or directory (os error 2)

Yes, giving the existing problems that makes sense.
But after running from the root, you do get the compiled javascript files right?

Nope, when running from the root, nothing gets built. It just exits with zero.

So basically, listing dependencies in the root rescript.json helps with resolving monorepo packages when running rescript build for a specific package, but it doesn’t build the packages when running rescript build from the root.

I figured that when I run npm exec -- rescript build from the root, it uses v11 for whatever reason. I’m going to clean this mess up so the repo only has v12 and report back on what’s going on when I run it from the root with v12.

I tried to update rescript-dnd to v12, but facing the same issues with @rescript/runtime and Pervasives.

Here is the branch: Update to rescript@12 by alex35mil · Pull Request #36 · shakacode/rescript-dnd · GitHub

And btw, rescript legacy build doesn’t work either.

With @rescript/runtime as a dependency in rescript.json:

❯ yarn run rescript legacy build
yarn run v1.22.15
$ /Users/Alex/Dev/rescript-dnd/node_modules/.bin/rescript legacy build
>>>> Start compiling
Error: /Users/Alex/Dev/rescript-dnd/node_modules/@rescript/runtime/rescript.json: No such file or directory>>>> Finish compiling (exit: 2)
error Command failed with exit code 2.

Without @rescript/runtime as a dependency I get the same Pervasives error.