@rescript/runtime dependency problems

I think the issue is with how pnpm resolves dependencies in a monorepo with isolated installs.

My use case:

Root node_modules/.pnpm:

  • contains rescript
  • contains @rescript/runtime

some/app package.json:

"devDependencies": {
  "rescript": "^12.0.0"
},

some/app node_modules:

  • contains rescript
  • :warning: does not contain @rescript/runtime
  • Vite import fails because the compiled source file contains
    import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js"

With pnpm’s isolated installs, a package can only import modules that appear in its own dependencies (or devDependencies), so from pnpm’s point of view some/app directly depends on @rescript/runtime and must declare it.

fix

some/app package.json:

"dependencies": {
  "@rescript/runtime": "^12.0.0"
},
"devDependencies": {
  "rescript": "^12.0.0"
},

not a fix

Adding rescript to dependencies does not solve the issue; you get the same error. Even if rescript itself depends on @rescript/runtime, pnpm will not expose @rescript/runtime as a direct dependency of some/app, so Node/Vite still cannot resolve it from some/app’s node_modules.

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@rescript/runtime'
1 Like

Yup, this sounds about right.
It is only @rescript/runtime code that will end up in your bundle so it does make sense to add that to “dependencies” and the compiler to “devDependencies”.

This does highlight a DX problem, I suppose.
Your need two packages in practice and those can conflict. Similar to how you can mix react 18 with react-dom 19. You want those in sync, a mismatch can lead to headaches.

This problem only really surfaces more clearly when you are using isolated installs.

wouldn’t this be sort of trivial to mitigate by having the compiler emit a warning if the two packages exist in package.json and are of different versions?