Skip to main content

Installation

This page is only about setup: install the packages, choose your decorator mode, and make sure your toolchain is configured correctly.

If you want to build a first working store after setup, continue with Getting Started.

yarn add mobx mobx-keystone

mobx-keystone requires mobx as a peer dependency, so both packages need to be installed.

If you are using React, add mobx-react-lite too:

yarn add mobx-react-lite

This library requires a more or less modern JavaScript environment to work, namely one with support for:

  • MobX 6, 5, or 4 (with its gotchas)
  • Proxies
  • Symbols
  • WeakMap/WeakSet

In other words, it should work on mostly anything except it won't work in Internet Explorer.

If you are using TypeScript:

  • Version 5.0+ is recommended (standard decorators).
  • Legacy decorators are also supported (experimentalDecorators: true).

Setup checklist

Before writing your first model, make sure your app setup matches these assumptions:

  • mobx is installed next to mobx-keystone.
  • Your TypeScript / Babel / SWC config consistently uses either standard decorators or legacy decorators.
  • If your app has a long-lived application store, registering it as a root store is recommended.
  • Your UI layer uses a MobX binding such as mobx-react-lite if you want React components to observe model changes.

Transpiler configuration

This library uses JavaScript decorators and class properties.

Standard decorators

Use this mode if you are on TypeScript 5+ and want standard decorators. For Babel, ensure class static blocks are transformed (for example via @babel/preset-env targets, or by adding @babel/plugin-transform-class-static-block).

tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": false,
"useDefineForClassFields": true
}
}

Legacy decorators

Use this mode if your project is on legacy decorators (experimentalDecorators: true).

tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": true
}
}

Next step

Once installation and transpiler setup are done, move on to Getting Started for the first working store.