Chromatic CLI
The Chromatic CLI manages the visual testing and review process.
Usage with Storybook
$ npx chromatic --project-token <your-project-token>
The CLI defaults to running with Storybook. It builds and uploads your Storybook to Chromatic’s cloud infrastructure, to start the publish and visual test workflows.
If you customize the way your Storybook runs, you may need to pass additional options. After the first run, the CLI will automatically ask you to add a script to your package.json.
If you don’t install chromatic as a dependency, npx automatically downloads and runs the latest version. This means you’ll always have the newest features but might experience slightly slower startup times due to the download.
Usage with Playwright or Cypress
When pairing Chromatic with Playwright or Cypress, you have to pass the corresponding flag: --playwright or --cypress. Chromatic captures an archive of your UI (DOM, styles, and assets) while Playwright or Cypress runs your E2E tests. The CLI uploads the archive to the Chromatic cloud infrastructure to run visual testing.
# For Chromatic with Playwright
$ npx chromatic --project-token <your-project-token> --playwright
# For Chromatic with Cypress
$ npx chromatic --project-token <your-project-token> --cypress
For Playwright and Cypress, we recommend installing the chromatic package as a dependency. This ensures that the CLI is in sync with the @chromatic-com/playwright or @chromatic-com/cypress package.
Installing
npm install chromatic --save-dev yarn add --dev chromatic pnpm add --save-dev chromatic Configuring the CLI
Chromatic CLI can be configured through options in ./chromatic.config.json file (recommended) placed at the root of your project folder and/or by passing CLI flags.
Some options are only available as flags. For a full list of available options, please refer to the configuration reference page.
Flags must be passed as --kebab-case whereas options are camelCase. Flags take precedence over configuration options. When passing a flag without value, it is treated as true. Where an array is accepted, specify the flag multiple times (once for each value).
Flags
-
Flags take precedence over options specified in the config file and GitHub Action.
-
Passing a flag without a value is treated as
true. e.g.:$ npx chromatic --dry-run -t <your-project-token> -
Where an
arrayis accepted, specify the flag multiple times (once for each value). e.g.:$ npx chromatic --externals "my-folder/**" --externals "another-folder/**" -t <your-project-token>
Chromatic Config File
The configuration file is stored in the root of your project folder as ./chromatic.config.json. You can use the --config-file flag to customize the Chromatic configuration file name and path.
If you aren’t using CI (yet), you just need the minimum setup:
{
"$schema": "https://www.chromatic.com/config-file.schema.json",
"projectId": "Project:..."
}
A full-featured ./chromatic.config.json file in a CI workflow where all changes to main happen through a pull request may look like this:
{
"$schema": "https://www.chromatic.com/config-file.schema.json",
"projectId": "Project:...",
"autoAcceptChanges": "main",
"exitOnceUploaded": true,
"externals": ["public/**"],
"onlyChanged": true,
"skip": "dependabot/**"
}
For unlinked projects that rely on the CI script to report build results, the recommended setup looks like this:
{
"$schema": "https://www.chromatic.com/config-file.schema.json",
"projectId": "Project:...",
"externals": ["public/**"],
"junitReport": true,
"onlyChanged": true
}
JSON schema for the config file
We provide a JSON schema for the Chromatic config file at: https://www.chromatic.com/config-file.schema.json. You can use this schema to validate your configuration file directly in your editor. To enable this, add the following to your settings.json.
This will give you IntelliSense suggestions as you type, and your editor will perform both structural and value verification.
{
"$schema": "https://www.chromatic.com/config-file.schema.json"
/* ... config options */
}
Authentication
Chromatic builds are authenticated using your project’s secret project token. You can access your project token from the Chromatic website during onboarding or from your project’s Manage page.
Continuous Integration
To set up CI, store your project token as the CHROMATIC_PROJECT_TOKEN environment variable or secret. The CLI automatically recognizes this variable, so you won’t have to provide it explicitly.
Visual Tests addon
For local builds with the Visual Tests addon, your personal OAuth token (which you used to authenticate the addon) is used instead of the project token.
Exit codes
| Exit code | Key | Description |
|---|---|---|
0 | OK | Exited successfully |
1 | BUILD_HAS_CHANGES | Chromatic build has (visual) changes |
2 | BUILD_HAS_ERRORS | Chromatic build has component errors |
3 | BUILD_FAILED | Chromatic build failed due to system error |
4 | BUILD_NO_STORIES | Chromatic build failed because it contained no stories |
5 | BUILD_WAS_LIMITED | Chromatic build was limited |
6 | BUILD_WAS_CANCELED | Chromatic build was canceled |
11 | ACCOUNT_QUOTA_REACHED | Chromatic account used all included snapshots |
12 | ACCOUNT_PAYMENT_REQUIRED | Chromatic account requires payment |
21 | STORYBOOK_BUILD_FAILED | Failed to run build-storybook script |
22 | STORYBOOK_START_FAILED | Failed to start Storybook |
23 | STORYBOOK_BROKEN | Unable to load Storybook or one of the stories |
101 | GIT_NOT_CLEAN | Git repository workspace not clean |
102 | GIT_OUT_OF_DATE | Git repository not up-to-date with remote |
103 | GIT_NO_MERGE_BASE | Git branch has no merge base |
104 | NPM_INSTALL_FAILED | npm or Yarn failed to install dependencies |
105 | NPM_BUILD_STORYBOOK_FAILED | npm or Yarn failed to run build-storybook script |
201 | FETCH_ERROR | HTTP fetch error |
202 | GRAPHQL_ERROR | GrahpQL API error |
210 | MISSING_DEPENDENCY | Dependency issue |
220 | VERIFICATION_TIMEOUT | Build verification timeout |
254 | INVALID_OPTIONS | Invalid options (flags) provided |
255 | UNKNOWN_ERROR | Unknown error |
Troubleshooting
I see “Chromatic: Failed to publish. Reason: self-signed certificate in certificate chain” when running the CLI on my machine.
This isn’t a Chromatic CLI issue. Check if your machine is using special security or network settings before running the CLI.
I see “ENOTFOUND” when running the CLI on my machine
By default, DNS resolution is handled by the environment system. If you are experiencing DNS issues (i.e., ENOTFOUND), the CLI will try to switch from the operating system DNS lookup (i.e., dns.lookup) to network DNS resolve (i.e., dns.resolve). If this also fails, the CLI will add CHROMATIC_DNS_FAILOVER_SERVERS to the list of available DNS servers and try again. For additional information regarding Node’s DNS implementation, please refer to their documentation.
Why are Git environment variables not working with the CLI?
If you’ve configured the Chromatic CLI to run with one of the Git environment variables (i.e., CHROMATIC_SHA, CHROMATIC_BRANCH, CHROMATIC_SLUG), you must configure all three. Otherwise, Chromatic will ignore them when running the build.
Flags to help diagnose build issues with the CLI
--no-interactive: When running the CLI locally, use this flag to get logs like you would in CI, which are more elaborate than the interactive logs. This is automatically enabled in CI, so adding it to a CI script is useless.--diagnostics-file: Before terminating the process, this dumps process context information tochromatic-diagnostics.json. This is the first place to look if you see things you didn’t expect. In a CI system, you’ll have to configure this file as a build artifact so you can download it. How to do this depends on your CI provider.--dry-run: Use this if you want to debug the CLI without actually publishing your Storybook or running a Chromatic build. Typically, you’d pair this with--diagnostics-file.--debug: This enables verbose logging and--no-interactive. Use this if you want to see the nitty-gritty details. Primarily useful if you have issues publishing (uploading) your Storybook to Chromatic.--trace-changed: Specifically for TurboSnap, you can use this flag to get a printed tree view of the dependencies between changed files (according to Git) and your story files.--only-story-names: If you have specific stories causing problems, you can use this flag to run a build for just those stories (one or more). If you don’t know which stories are available, you can use--listto print a list of all stories in your Storybook, though it will require running a Chromatic build.
I see “No installationId found for repositoryId” when running the CLI
Chromatic can’t reach the git repository linked to your project. This usually means one of three things:
- The repository connection has lapsed. Check whether your organization’s permissions for the Chromatic app have changed.
- The repository was renamed or deleted, so Chromatic can no longer find it at the path it has on file.
- Your git access token is no longer valid. Log out of Chromatic and log back in to refresh it.
Also, confirm that git is initialized in the directory you’re running the CLI from (git status).
I see “Failed to build Storybook”
This is a problem with your Storybook build, not with Chromatic. Chromatic builds your Storybook in production mode, so a package that works in development mode but breaks in a production build will fail here, while running fine locally with storybook dev.
Reproduce it locally the same way Chromatic does:
npm run build-storybook
npx http-server storybook-static -oIf that fails, fix the build error and re-run. If it succeeds, run Chromatic with diagnostics to capture more detail:
npx chromatic --project-token=<TOKEN> --dry-run --debug --diagnostics-fileI see “Failed to extract stories from your Storybook”
Your Storybook contains a runtime error. The full message may look like this:
✖ Failed to extract stories from your Storybook
This is usually a problem with your published Storybook, not with Chromatic.
Build and open your Storybook locally and check the browser console for errors.
Visit your published Storybook at https://<subdomain>.chromatic.com
The following error was encountered while running your Storybook:
Error: page.evaluate: ReferenceError: Cannot access 'it' before initializationThe message doesn’t say which story is responsible, and because stories load on demand, opening your published Storybook may not surface the error in the console at all.
To find the offending story:
-
Open your published Storybook’s
iframe.html(the URL is in the CLI output, with/iframe.htmlappended). -
In the browser console, run:
await (window.__STORYBOOK_PREVIEW__?.extract?.() ?? __STORYBOOK_PREVIEW__.extract()); -
The console output names the story that threw.
Fix the runtime error in that story, then rerun your build.
I see “Build script not found”
The CLI couldn’t find a build-storybook script in your package.json:
✖ Build script not found
The CLI didn't find a script called "build-storybook" in your package.json.Add it:
{
"scripts": {
"build-storybook": "storybook build",
"chromatic": "chromatic"
}
}If your build script has a different name, point the CLI at it with buildScriptName instead of renaming it.
I see “Failed to publish your built Storybook — Invalid Storybook build”
Chromatic detected that the build output isn’t a valid Storybook and stopped before uploading, so there’s no additional logging to inspect.
Build your Storybook locally to confirm it produces valid output. If it does, build it as a separate step in CI and hand the output directory to Chromatic rather than letting Chromatic build it:
npm run build-storybook
npx chromatic --storybook-build-dir=storybook-staticI see “Failed to authenticate” and I’m on a corporate network
This usually indicates a TLS problem. Proxies that intercept HTTPS traffic and present their own certificate can break the CLI’s connection to Chromatic.
If the CLI worked previously but has started failing without any changes on your side, your network, DNS, or firewall configuration likely changed.
Check whether your machine can reach index.chromatic.com with a valid TLS certificate. If your organization uses a corporate certificate, your security team will need to allow the connection.
See also local certificate errors.
I see “Failed to authenticate (INTERNAL_SERVER_ERROR: No app with code ’…’ found)”
The project token being passed doesn’t match any Chromatic project. Almost always a configuration problem rather than an outage:
- Confirm the token against the one on your project’s Manage page.
- If the token comes from an environment variable or a secrets manager, confirm the value arriving at the CLI is the raw token and hasn’t been wrapped, encrypted, or truncated in transit.
- If the token was reset, update every place it’s configured.
I see “Error: Unknown argument” and I’m using the Angular CLI
Error: Unknown argument: /tmp/chromatic--1234-e5X6a7M8p9L0eThe Angular CLI rejects the temporary output directory that Chromatic passes when it builds your Storybook for you. Build Storybook as its own step and pass the result to Chromatic instead:
{
"scripts": {
"build-storybook": "ng run components:build-storybook",
"chromatic": "npm run build-storybook && npx chromatic --storybook-build-dir=static-storybook"
}
}I see “Some chunks are larger than 500 kBs”
This is a warning from your bundler about your Storybook’s output size, not a Chromatic error. It often appears alongside a failing or slow build.
Options, roughly in order of effort:
-
Use dynamic
import()to split large modules so they load on demand. -
Configure chunking explicitly —
build.rollupOptions.output.manualChunksfor Vite,optimization.splitChunksfor webpack. -
Raise the warning threshold if the size is expected. In Vite:
vite.config.jsexport default { build: { chunkSizeWarningLimit: 1000, // KB }, };This changes only the warning threshold, not the chunk sizes.
If your build is also timing out, see CHROMATIC_TIMEOUT and STORYBOOK_BUILD_TIMEOUT, and consider passing a prebuilt Storybook with --storybook-build-dir.
I see “Failed to publish your built Storybook — Sentinel file ‘files-copied.txt’ not OK”
Chromatic reuses unchanged files from your previous build instead of re-uploading them. This error means one or more of those files failed to copy.
Re-run the build. If it keeps failing, disable file reuse for that build:
npx chromatic --no-file-hashingand contact support so we can look into it.
I see “NoSuchKey” in my —debug output
A NoSuchKey 404 for .chromatic/files-copied.txt in verbose output is expected and harmless. Chromatic polls for that file while reusing unchanged files from your previous build, so it’s absent until the copy finishes. It doesn’t affect your build.
I see “Unhandled promise rejection: Invalid version”
Unhandled promise rejection: Invalid version: "x"This comes from npm, not Chromatic. The version field in your package.json must be parseable by node-semver — that is, it must follow semantic versioning. A leading = or v is stripped, but any other scheme fails.
Update the version to a valid semver string.
I see “ReferenceError: <something> is not defined”
For example:
ReferenceError: React is not defined
ReferenceError: _jsx is not defined
ReferenceError: IDBIndex is not definedA dependency isn’t declared, isn’t installed, or is declared incorrectly, so it’s missing from the production build Chromatic renders.
-
Confirm your Storybook builds and serves locally:
npm run build-storybook npx http-server storybook-static -o -
Run Storybook’s health check to catch mismatched
@storybook/*versions:npx storybook@latest doctor -
Check that the missing dependency is declared in
package.jsonand that its configuration (for example, your Vite or webpack config) is complete.