Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react v15.5.4 warning #5705

Closed
39Er opened this issue May 5, 2017 · 6 comments
Closed

react v15.5.4 warning #5705

39Er opened this issue May 5, 2017 · 6 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@39Er
Copy link

39Er commented May 5, 2017

I used babel-preset-react,but it shows the follow warning:

react.js:3287

Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.

Warning: LazyRenderBox: React.createClass is deprecated and will be removed in version 16. Use plain JavaScript classes instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in `replacement.

  • node.js v4.4.5

  • react v15.5.4

  • babel 6.24.0

@babel-bot
Copy link
Collaborator

Hey @39Er! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@loganfsmyth
Copy link
Member

These warnings are not Babel related, they are just warnings that React itself shows because you are using features that React is changing.

@39Er
Copy link
Author

39Er commented May 5, 2017

Oh,I see ,thank U

@adammunoz
Copy link

@loganfsmyth

I do think it's related to Babel.

React implements the following check in order to trigger warnings for every access to the PropTypes key in the React object:

Object.defineProperty(React, 'PropTypes', {
  get: function() {
    lowPriorityWarning(didWarnPropTypesDeprecated, 'Accessing PropTypes via the main React package is deprecated,' + ' and will be removed in  React v16.0.' + ' Use the latest available v15.* prop-types package from npm instead.' + ' For info on usage, compatibility, migration and more, see ' + 'https://fb.me/prop-types-docs');
    didWarnPropTypesDeprecated = true;
    return ReactPropTypes;
  }
});

As you can see below because Babel iterates over all properties in the React object, it reads the PropTypes key, triggering the warnings.

function _interopRequireWildcard(obj) {
        if (obj && obj.__esModule) {
            return obj;
        } else {
            var newObj = {};
            if (obj != null) {
                for (var key in obj) {
                    if (Object.prototype.hasOwnProperty.call(obj, key))
                        newObj[key] = obj[key];
                }
            }
            newObj.default = obj;
            return newObj;
        }
    }

@jridgewell
Copy link
Member

This shouldn't be Babel. Try this:

const React = {};
Object.defineProperty(React, 'PropTypes', {
  get: function() {
    throw new Error('PropTypes');
  }
});

function _interopRequireWildcard(obj) {
  if (obj && obj.__esModule) {
    return obj;
  } else {
    var newObj = {};
    if (obj != null) {
      for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key))
          newObj[key] = obj[key];
      }
    }
    newObj.default = obj;
    return newObj;
  }
}

_interopRequireWildcard(React);

@julienw
Copy link
Contributor

julienw commented Feb 13, 2018

FTR It's been fixed in #6850

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 15, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

6 participants