Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

warning

BerkeleyTrue28.1mMIT4.0.3TypeScript support: definitely-typed

A mirror of Facebook's Warning

warning, facebook, react, invariant

readme

Warning npm version

Greenkeeper badge A mirror of Facebook's Warning

Usage

npm install warning
// some script
var warning = require('warning');

var ShouldBeTrue = false;

warning(
  ShouldBeTrue,
  'This thing should be true but you set to false. No soup for you!'
);
//  'This thing should be true but you set to false. No soup for you!'

Similar to Facebook's (FB) invariant but only logs a warning if the condition is not met. This can be used to log issues in development environments in critical paths. Removing the logging code for production environments will keep the same logic and follow the same code paths.

FAQ (READ before opening an issue)

Why do you use console.error instead of console.warn ?

This is a mirror of Facebook's (FB) warning module used within React's source code (and other FB software). As such this module will mirror their code as much as possible.

The descision to use error over warn was made a long time ago by the FB team and isn't going to change anytime soon.

The source can be found here: https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/__forks__/warning.js The reasoning can be found here and elsewhere: https://github.com/facebook/fbjs/pull/94#issuecomment-168332326

Can I add X feature?

This is a mirror of Facebook's (FB) warning and as such the source and signature will mirror that module.

If you believe a feature is missing than please open a feature request there. If it is approved and merged in that this module will be updated to reflect that change, otherwise this module will not change.

Use in Production

It is recommended to add babel-plugin-dev-expression with this module to remove warning messages in production.
















Don't Forget To Be Awesome

changelog

4.0.3 (2019-02-09)

Bug Fixes

  • incorrect formatting of message with arguments (b188176)

4.0.2 (2018-08-17)

Bug Fixes

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

4.0.1 (2018-05-30)

Bug Fixes

  • add var printWarning = to comply with ES5 strict mode (677dcfa), closes #25

4.0.0 (2018-05-22)

Bug Fixes

Chores

  • LICENSE: Change from BSD modified to MIT (5a63a1b)

BREAKING CHANGES

  • LICENSE: Change License to MIT from BSD+patents
  • This changes the internal workings. A major release is made to ensure minimal effect on downstream users.

3.0.0 (2015-10-04)

BREAKING CHANGE

  • package.json correct license field (6bd7ad5)

2.1.0 (2015-10-04)

Features

2.0.0 (2015-07-11)

BREAKING CHANGE

1.0.2 (2015-05-30)

Bug Fixes