Mirage JS is a client-side server library for JavaScript applications, designed to mock API requests during development, testing, and prototyping. It intercepts network requests (XHR and Fetch) and returns defined responses, allowing front-end development to proceed independently of a live backend. The current stable version is 0.1.48, with an experimental 0.2.x alpha branch actively exploring integration with MSW as an alternative interceptor to the default Pretender. Mirage JS is distinguished by its full-featured ORM-like data layer, including models, factories, and serializers, which enables complex data relationships and realistic mock API interactions, setting it apart from simpler request mocking tools. Its release cadence appears to be several patches per month on the 0.1.x branch, with larger architectural changes being developed in the 0.2.x alpha line.
npm install miragejsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a basic Mirage JS server with models, factories, seeds, and routes, then making a mock API call.
Change `const server = createServer(...)` to `const server = await createServer(...)`.
For stable production use, remain on the v0.1.x branch. If experimenting with v0.2.x, frequently review changelogs and prepare for API adjustments.
Always call `server.shutdown()` in your test teardown (e.g., `afterEach` or `afterAll` in testing frameworks) to clean up the server instance and clear intercepted requests.
Ensure all relevant network traffic goes through Fetch or XHR. If specific libraries use non-standard request methods, consider mocking those libraries directly or adjusting your application's network layer.
Update your import statements to use ESM syntax: `import { createServer } from 'miragejs';`. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions for ESM.Ensure `createServer` is `awaited`: `const server = await createServer({ ... });`.Verify that every model you intend to create with `server.create()` has a corresponding factory defined in the `factories` object of your server configuration with a matching key.
Add a `this.get('/api/nonexistent-route', ...)` or appropriate `this.post`/`put`/`delete` route to your `routes()` definition to handle the request. Alternatively, use `this.passthrough('/api/nonexistent-route')` if it should bypass Mirage and go to the real backend.No dependency data recorded yet.