Migrate to ReScript 13
This guide lists the changes that need action when upgrading from ReScript 12, up to 13.0.0-alpha.7. Upgrading from ReScript 11? Follow the v12 migration guide first. If something is missing, please open an issue or send a pull request.
Before You Upgrade
Node.js 22 or newer is required.
macOS on Intel is no longer supported. Stay on ReScript 12 there.
APIs deprecated in ReScript 12 are removed, for example
List.has,Error,Exnand theCharmodule. On the latest 12.x release, runnpx rescript-tools migrate-all .to apply the automatic migrations, then fix any remaining deprecation warnings.
Dependencies
Belt
Belt is now a separate package. Install @rescript/belt in the same version as rescript. During the v13 prereleases, that's the next-13 tag:
SHnpm install @rescript/belt@next-13
Then add it to rescript.json:
JSON{
"dependencies": ["@rescript/belt"]
}
Belt functions that returned undefined<'a>, such as Belt.Array.getUndefined, are removed. Use the versions that return option<'a>, such as Belt.Array.get.
Js
The Js namespace is removed. Use the standard library modules instead, such as Array, String, Dict and JSON.
Build System and CLI
rescript runs a new build system. Check your scripts for these changes:
rescript-legacyis removed.The
--devand--create-sourcedirsflags andrescript build -ware removed. Userescript watchto watch.A
rescript.jsonwith duplicate keys, or withnamespace-entrybut nonamespace, is an error.A failing
--after-buildcommand fails the build.--filteronly accepts common regular expression syntax.RESCRIPT_BSC_EXEis no longer read.The
-uncurriedand-ppcompiler flags are removed. Delete them fromcompiler-flags.
Build Configuration
Configuration File and Keys
Rename bsconfig.json to rescript.json, and rename these keys:
| Legacy key | Current key |
|---|---|
bs-dependencies | dependencies |
bs-dev-dependencies | dev-dependencies |
bsc-flags | compiler-flags |
The old file name and keys still work, but print deprecation warnings.
Remove external-stdlib. It's no longer supported.
Module Format
esmodule is now the default when package-specs is omitted. To keep CommonJS output, set it explicitly:
JSON{
"package-specs": {
"module": "commonjs",
"in-source": true
}
}
Replace legacy module names:
es6→esmoduleandcjs→commonjs. The old names still work, but print deprecation warnings.es6-global→esmodule. The old name is now an error.
Multiple Output Formats
When you emit several formats to the same location, give each its own suffix. Specs with the same suffix are now rejected:
JSON{
"package-specs": [
{ "module": "esmodule", "suffix": ".mjs" },
{ "module": "commonjs", "suffix": ".cjs" }
]
}
See Build Configuration for all options.
Language Changes
Removed Syntax
| Removed | Use instead |
|---|---|
(. a, b) => ... uncurried functions | (a, b) => ... |
%re("/b/g") | Regular expression literals: /b/g |
%debugger | debugger() |
%external(name) | %raw, or a binding such as @val external |
@taggedTemplate | The taggedTemplate<'param, 'output> type |
@deriving(abstract), @deriving(jsConverter) | Records and polymorphic variants |
@ocaml.warning and the other @ocaml.* forms | @warning and the other unprefixed forms |
@ocaml.doc, @ns.doc | /** */ doc comments |
Record syntax for a dict, {foo: 1} | dict{"foo": 1} |
Other Changes
breakandcontinueare keywords. Rename identifiers with these names, or escape them, as in\"break".@unboxedgoes on the variant type, not on a constructor. For a constructor whose payload is an inline record with one field, this unboxes the value to that field. Give the record a named type to keep the object.Object fields can only be assigned when they are marked
@set, as in{@set "name": string}. The other@getand@setforms on object types are removed.@this this => async arg => ...now defines a method that returns an async function. For an async method, write@this async (this, arg) => ....Jsx.componentis an abstract type. To use a plain function as a component, define it with@react.componentor wrap it inReact.component(...).Nested functions other than
makeare no longer exported to JavaScript as top-levelA$B$fvalues.Coercing another type into a private record or variant is an error.
Records with
@as("0"),@as("1"), … fields compile to JavaScript arrays. Rest patterns, coercions and untagged variants that would treat them as objects are errors.Tagged template literals can't be used in patterns.
Invalid escapes in string and template literals, and malformed UTF-8 in doc comments, are errors.
\"_"is no longer a valid identifier.
Standard Library
The new
Temporalmodule shadows project modules namedTemporal. Rename yours. Nested modules namedTemporalare exported to JavaScript as$$Temporal.Typed array types such as
Int8Array.tare no longer interchangeable. Upcast with:> TypedArray.t<_>to use the genericTypedArrayfunctions.TypedArray.mapandTypedArray.mapWithIndexkeep the element type.Int.fromStringandFloat.fromStringno longer take a radix. They parse hexadecimal, binary and exponential notation, such as0x1F, directly, and are stricter.Intl.Collator.comparereturnsOrdering.tinstead ofint.Iterators are typed as
Iterator.t<'yield, 'return, 'next>.fromIteratoronArray,Dict,MapandSetis nowfromIterable; coerce iterators to it, as inArray.fromIterable((map->Map.keys :> Iterable.t<_>)).toArray,toArrayWithMapperandforEachmoved fromIteratortoIteratorObject, the type thatMap.keys,Array.valuesand similar functions return.Int.Refis removed. Userefvalues directly.Custom externals that use removed primitives, such as
%incror%obj_field, are rejected.