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.
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.
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'
}
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.
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.
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"
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.
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)
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 -
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'
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?