You can install XState from NPM or Yarn, or you can embed the <script> directly from a CDN.

Package Manager

npm install xstate@latest --save
# or:
yarn add xstate@latest --save


You can include XState directly from the unpkg CDN:

<script src=""></script>

<!-- Optional: XState interpreter -->
<script src=""></script>

The variable XState will be available globally, which will give you access to the top-level exports. If you included the interpreter, the variable XStateInterpreter will be available globally as well.

const { Machine, actions } = XState; // global variable: window.XState
const { interpret } = XStateInterpreter; // global variable: window.XStateInterpreter

const lightMachine = Machine({
  // ...

const lightService = interpret(lightMachine);