{"id":15320,"library":"ember-cli-mirage","title":"Ember CLI Mirage","description":"Ember CLI Mirage is an Ember CLI addon that provides a client-side server, enabling developers to build, test, and prototype Ember applications without a real backend. It intercepts HTTP requests made by an Ember app and responds with mocked data, making it invaluable for rapid development, consistent testing, and demonstrating features in isolation. The current stable version is 3.0.4, with frequent patch and minor releases, reflecting active maintenance and responsiveness to the Ember ecosystem. A key differentiator is its deep integration with Ember CLI and Ember Data, allowing for auto-discovery of models and simplified setup. It leverages the standalone MirageJS library for its core mocking capabilities, providing a robust and flexible API for defining API endpoints, factories, and serializers.","status":"active","version":"3.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/miragejs/ember-cli-mirage","tags":["javascript","ember-addon","pretender","prototype","server","testing"],"install":[{"cmd":"npm install ember-cli-mirage","lang":"bash","label":"npm"},{"cmd":"yarn add ember-cli-mirage","lang":"bash","label":"yarn"},{"cmd":"pnpm add ember-cli-mirage","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core mocking library; became a peer dependency in v3.0.0.","package":"miragejs","optional":false},{"reason":"Required for integration with Ember Data models.","package":"@ember-data/model","optional":false},{"reason":"Used for setting up Mirage in testing environments.","package":"@ember/test-helpers","optional":false},{"reason":"Required for integration with Ember Data (older versions or compatibility).","package":"ember-data","optional":false},{"reason":"Used in testing environments, particularly with QUnit.","package":"ember-qunit","optional":false},{"reason":"Core Ember.js framework dependency.","package":"ember-source","optional":false}],"imports":[{"note":"This helper is specifically for test setups and is imported from `test-support`. Available since v3.0.0-alpha.3 with TypeScript declarations.","wrong":"import { setupMirage } from 'ember-cli-mirage';","symbol":"setupMirage","correct":"import { setupMirage } from 'ember-cli-mirage/test-support';"},{"note":"Since v3.0.0-alpha.2, you must import `createServer` directly from `miragejs` and use it within your `mirage/config.js`. The `ember-cli-mirage` Server class was removed.","wrong":"import { Server } from 'ember-cli-mirage'; new Server(...);","symbol":"createServer","correct":"import { createServer } from 'miragejs';"},{"note":"For custom HTTP responses, `Response` should be imported directly from `miragejs`. Re-exports from `ember-cli-mirage` were removed in v3.0.0-alpha.1.","wrong":"import Response from 'ember-cli-mirage/response';","symbol":"Response","correct":"import { Response } from 'miragejs';"}],"quickstart":{"code":"import Application from '@ember/application';\nimport config from './config/environment';\nimport loadInitializers from 'ember-load-initializers';\n\n// app/mirage/config.js\n// This file is automatically loaded by ember-cli-mirage.\n// It's where you define your API routes, factories, and serializers.\nexport default function() {\n  this.get('/posts', function(schema, request) {\n    return schema.posts.all();\n  });\n\n  this.post('/posts', function(schema, request) {\n    let attrs = JSON.parse(request.requestBody);\n    return schema.posts.create(attrs);\n  });\n\n  this.passthrough('/users/**'); // Example of proxying requests\n}\n\n// tests/test-helper.js (example usage in a test)\nimport resolver from './helpers/resolver';\nimport { setApplication } from '@ember/test-helpers';\nimport { start } from 'ember-qunit';\nimport { setupMirage } from 'ember-cli-mirage/test-support';\n\nsetApplication(Application.create(config.APP));\n\nmodule('Integration | Component | my-component', function(hooks) {\n  setupApplicationTest(hooks);\n  setupMirage(hooks); // This will start Mirage for your tests\n\n  test('it renders posts', async function(assert) {\n    this.server.createList('post', 3); // Create some mock data\n    await render(hbs`<MyComponent />`);\n    assert.dom('.post').exists({ count: 3 });\n  });\n});\n","lang":"typescript","description":"This quickstart demonstrates how to install `ember-cli-mirage`, define basic mock API routes in `mirage/config.js`, and integrate `setupMirage` into an Ember QUnit test to provide mock data."},"warnings":[{"fix":"Run `npm install miragejs` (or `yarn add miragejs`) in your project root after upgrading to `ember-cli-mirage@3.x`.","message":"`miragejs` is now a peer dependency and must be explicitly installed. This means you need to add `npm install miragejs` to your project.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update your `mirage/config.js` to use `import { createServer } from 'miragejs';` and pass your config to it, instead of instantiating `Server` directly from `ember-cli-mirage`.","message":"The `ember-cli-mirage` Server class has been removed. You must now use `createServer` imported directly from `miragejs` in your `mirage/config.js`.","severity":"breaking","affected_versions":">=3.0.0-alpha.2"},{"fix":"Replace `import { Response } from 'ember-cli-mirage/response';` (and similar re-exports) with `import { Response } from 'miragejs';`.","message":"Deprecated re-exports from `ember-cli-mirage` (like `Response`, `Factory`, `Model`, etc.) which were originally from `miragejs` have been removed. You must import these directly from `miragejs`.","severity":"breaking","affected_versions":">=3.0.0-alpha.1"},{"fix":"Ensure your project meets the minimum requirements: upgrade Ember.js to 3.28 or higher and Node.js to 16 or higher. Run `npx ember-cli-update` for assistance.","message":"Support for older Ember.js and Node.js versions has been dropped. `ember-cli-mirage@3.x` requires Ember.js v3.28+ and Node.js v16+.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always include `setupMirage(hooks);` within your QUnit or Mocha `module()` setup function for tests that interact with Mirage.","message":"In a testing environment, `setupMirage(hooks)` should be called to properly initialize the Mirage server for each test module. For acceptance tests, `setupApplicationTest(hooks)` also initializes Mirage if configured.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run `npm install miragejs` or `yarn add miragejs` to add the core library to your project's dependencies.","cause":"The `miragejs` package is a peer dependency since `ember-cli-mirage@3.x` but has not been installed.","error":"Module not found: Error: Can't resolve 'miragejs'"},{"fix":"Change your `mirage/config.js` to import `createServer` from `miragejs` and call it with your config function: `import { createServer } from 'miragejs'; export default function() { createServer({ environment: 'test', routes() { /* ... */ } }); }`.","cause":"Attempting to instantiate `Server` from `ember-cli-mirage` in `mirage/config.js`, which was removed in v3.0.0-alpha.2.","error":"TypeError: (0 , ember_cli_mirage__WEBPACK_IMPORTED_MODULE_2__.Server) is not a constructor"},{"fix":"Ensure `setupMirage(hooks)` is called for the current test module, and that any server interactions are within `beforeEach`, `afterEach`, or `test` blocks where `this.server` is guaranteed to be available.","cause":"This often occurs when `this.server.create(...)` or `this.server.schema(...)` is called outside the context where Mirage's server is properly initialized, such as within a test hook but before `setupMirage` has run, or in an incorrect context.","error":"TypeError: Cannot read properties of undefined (reading 'schema') in MirageJS"}],"ecosystem":"npm"}