License: MIT

Language: JavaScript


Build Status

A mirror of Facebook's invariant (e.g. React, flux).

A way to provide descriptive errors in development but generic errors in production.


With npm do:

npm install invariant

invariant(condition, message)

var invariant = require('invariant');

invariant(someTruthyVal, 'This will not throw');
// No errors

invariant(someFalseyVal, 'This will throw an error with this message');
// Error: Invariant Violation: This will throw an error with this message

Note: When process.env.NODE_ENV is not production, the message is required. If omitted, invariant will throw regardless of the truthiness of the condition. When process.env.NODE_ENV is production, the message is optional – so they can be minified away.


When used with browserify, it'll use browser.js (instead of invariant.js) and the envify transform will inline the value of process.env.NODE_ENV.


The node version is optimized around the performance implications of accessing process.env. The value of process.env.NODE_ENV is cached, and repeatedly used instead of reading process.env. See Server rendering is slower with npm react #812

Project Statistics

Sourcerank 18
Repository Size 27.3 KB
Stars 590
Forks 44
Watchers 6
Open issues 7
Dependencies 4
Contributors 10
Tags 13
Last updated
Last pushed

Top Contributors See all

Andres Suarez Jan Kassens Polgár András Clemens Akens NothingEverHappens Alex McLeod Amila Welihinda Nick Williams Anthony Ng Harry Moreno

Packages Referencing this Repo

Latest release 2.2.4 - Updated - 590 stars
WebJar for invariant
Latest release 2.2.3 - Updated - 590 stars

Recent Tags See all

v2.2.4 March 13, 2018
v2.2.3 February 19, 2018
v2.2.2 November 15, 2016
v2.2.1 March 09, 2016
v2.2.0 November 17, 2015
v2.1.3 November 17, 2015
v2.1.2 October 27, 2015
v2.1.1 September 21, 2015
v2.1.0 June 03, 2015
v2.0.0 February 21, 2015
v1.0.2 September 24, 2014
v1.0.1 September 24, 2014
v1.0.0 September 24, 2014

Interesting Forks See all

JavaScript - Last pushed - 1 stars - 2 forks

Something wrong with this page? Make a suggestion

Last synced: 2018-03-18 16:28:16 UTC

Login to resync this repository