@rescript/runtime dependency problems

Can we make runtime@12 rc or stable? i have to do pnpm add @rescript/runtime@ci to match the 12.0 release now

good catch @xfcw! It’s now listed as latest and should be kept in sync in the future.

I’m curious, what do you use @rescript/runtime for?

1 Like

isn’t @rescript/runtime required now that it was separated from rescript? I tend to do have rescript under devDependencies and @rescript/runtime under dependencies. if I try to build my monorepo after removing it from one of the projects:

ā€œRollup failed to resolve import ā€œ@rescript/runtime/lib/es6/Stdlib.jsā€ fromā€¦ā€

No no, just use rescript as a dependency like before and it’ll work! Direct use of @rescript/runtime is meant for people developing libraries that are meant to be consumed by js/ts users, this way the final users don’t have to depend on the whole compiler package.

2 Likes

Are you using isolated installs with your package manager?

How does your setup roughly look like?

really? it literally won’t build without it. it’s a pnpm monorepo, one is a lib and one is an app that uses the lib, both are rescript 12

it’s actually vite that fails, the others seem to build fine

[vite]: Rollup failed to resolve import ā€œ@rescript/runtime/lib/es6/Stdlib.jsā€ from ā€œā€¦/packages/app/src/somefile.resā€

heh, no, esbuild fails as well:

getting tons of these:

✘ [ERROR] Could not resolve "@rescript/runtime/lib/es6/Stdlib_Option.js"

    lib/es6/src/foundation/foundation_duration.res.js:3:31:
      3 │ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
        ╵                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@rescript/runtime/lib/es6/Stdlib_Option.js" as external to exclude it from
  the bundle, which will remove this error and leave the unresolved path in the bundle.

✘ [ERROR] Could not resolve "@rescript/runtime/lib/es6/Primitive_exceptions.js"

    lib/es6/src/foundation/foundation_duration.res.js:4:38:
      4 │ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
        ╵                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@rescript/runtime/lib/es6/Primitive_exceptions.js" as external to exclude
  it from the bundle, which will remove this error and leave the unresolved path in the bundle.

I recently had a similar thing with bun isolated installs.
The runtime wasn’t found by vite and I had to work around that.
Can you create a new discussion for this? That feels like worth talking more in depth about.
We should probably not hijack this thread for that.

2 Likes

Moved the posts here into a separate topic.

It should work now:

pnpm info rescript dependencies
{ '@rescript/runtime': '12.0.0' }
pnpm info rescript optionalDependencies
{
  '@rescript/linux-x64': '12.0.0',
  '@rescript/win32-x64': '12.0.0',
  '@rescript/darwin-x64': '12.0.0',
  '@rescript/linux-arm64': '12.0.0',
  '@rescript/darwin-arm64': '12.0.0'
}
1 Like

i don’t know what you mean when you say ā€œit should work nowā€. your commands give the same output for me, but it still doesn’t build/bundle unless i have @rescript/runtime. is this a pnpm-related issue?

Sorry, I should have written ā€œif the missing npm tag was actually the issue, it should work now to install without explicitly adding @rescript/runtimeā€.

What’s actually the issue is hard to say without a repro.

maybe the issue is i have rescript under devDeps? which i thiink SHOULD be right but maybe isn’t? the tooling is conceptually for devDeps

That sounds like it.

We suggest on the installation page to do a normal install:

Mainly because of the runtime.

1 Like

Since rescript includes the runtime, it should be a regular dependency.

i don’t agree with this. since the runtime was actually separated, the right thing to do is keep rescript under devDeps and runtime under deps. there’s zero reason to install tooling in a deployed production environment, you only need the runtime. the right suggestion would be to do what i already do, definitely. the docs should be changed to reflect this.

1 Like

The compiler got split per platform so it doesn’t add too much weight and if your project is very size sensitive, you probably use a tree shaker anyway! So I’d say the recommended setup is simple and does suit most requirements, but of course you can also use your setup which is correct too!

I have the same problem with SvelteKit/Vite.

[plugin:vite:import-analysis] Failed to resolve import "@rescript/runtime/lib/es6/Stdlib_Option.js" from "src/lib/some/file". Does the file exist?

I have rescript installed as regular dependency (not dev) at version 12.0.1. Also, looking into node_modules it looks like @rescript/runtime is not installed for some reason. Under @rescript I see only webapi package (which I’ve installed alongside so it’s expected to be there)

And under rescript I can see cli, docs, and ninja but not runtime

Explicitly adding @rescript/runtime fixes the issue but from what I understand from this thread it’s not the intended behavior

EDIT: Forgot to mention that I use Bun as bundler

EDIT 2: In case anyone like me has this issue, I fixed it by changing to hoisted install in bunfig.toml

[install]
linker = "isolated"
2 Likes

With some hackery you can keep using hoisted:

in your vite.config.js add:

// Resolve @rescript/runtime using Bun's module resolution
const rootPath = path.resolve(import.meta.dirname, "../.."); // rootPath because this config lives in a package subfolder
const rescriptPackage = path.dirname(Bun.resolveSync("rescript/package.json", rootPath));
const runtimePackage = path.dirname(Bun.resolveSync("@rescript/runtime/package.json", rescriptPackage));

// later in the config:
export default defineConfig({
  resolve: {
      alias: {
        "@rescript/runtime": runtimePackage,
      },
    }
})

not ideal I admit.

2 Likes

Hmm, interesting. But at this point just adding @rescript/runtime as a dependency seems like a more straightforward solution (and, from my understanding of isolated installs it seems to be the preferred method. If the package relies on some dependency, regardless where it comes from, we should declare it explicitly)