lundi 16 avril 2018

React App Crashing Due to undefined PropTypes.node

I ran into an issue today while working on the node.js + react based project was created with react v.15.0.0 , it has several deprecated features so I upgraded the project to use react v.16.2.0.

And now it is crashing and it cannot be compiled with webpack no more :(

I have the error message as:

    TypeError: Cannot read property 'node' of undefined
[3]     at Object.defineProperty.value (/Volumes/Develop/MyPortfolio/edward/dist/server.js:528:40)
[3]     at __webpack_require__ (/Volumes/Develop/MyPortfolio/edward/dist/server.js:20:30)
[3]     at Object.<anonymous> (/Volumes/Develop/MyPortfolio/edward/dist/server.js:406:22)
[3]     at __webpack_require__ (/Volumes/Develop/MyPortfolio/edward/dist/server.js:20:30)
[3]     at Object.defineProperty.value (/Volumes/Develop/MyPortfolio/edward/dist/server.js:342:16)
[3]     at __webpack_require__ (/Volumes/Develop/MyPortfolio/edward/dist/server.js:20:30)
[3]     at Object.<anonymous> (/Volumes/Develop/MyPortfolio/edward/dist/server.js:185:14)
[3]     at __webpack_require__ (/Volumes/Develop/MyPortfolio/edward/dist/server.js:20:30)
[3]     at Object.defineProperty.value (/Volumes/Develop/MyPortfolio/edward/dist/server.js:56:16)
[3]     at __webpack_require__ (/Volumes/Develop/MyPortfolio/edward/dist/server.js:20:30)
[3] [nodemon] app crashed - waiting for file changes before starting...

I traced back to /my project/dist/server.js file, this is the line that caused the crashing :

ExternalLink.propTypes = {
      children: _react2.default.PropTypes.node
    };

And _react2 is declared as :

var _react = __webpack_require__(3);

var _react2 = _interopRequireDefault(_react);

I have did some research and found that React 16.x has a separate package for the type check 'Prop-Types', I actually tried swap the old function with the new one like this:

   var _propType = require("prop-types");

    ExternalLink.propTypes = {
      children: _propType.default.PropTypes.node
    };

Still no luck, I am out of idea at this moment, would appreciate if someone can offer suggestions or workaround on this. Thanks.




Aucun commentaire:

Enregistrer un commentaire