简体   繁体   中英

Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined

I created a react-app which I deployed online with npm run build , now everything locally works fine but when I try to load a page on my app it gives a error in Container.js ( no idea what this file is and what it does )

i've tried to reinstall all the node_modules without any result so I cloned my repo fresh but still without any result

Container.js:

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _reactRedux = require('react-redux');

var _Container = require('../components/Container');

var _Container2 = _interopRequireDefault(_Container);

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : {
    default: obj
  };
}
/**
 * src/containers/Container.jsx
 */


var mapStateToProps = function mapStateToProps(store, ownProps) {
  return {
    items: store[ownProps.reduxStoreName].content[ownProps.reduxUid].filter(function (item) {
      return item.parentId === ownProps.itemId;
    })
  };
};

exports.default = (0, _reactRedux.connect)(mapStateToProps)(_Container2.default);

Error in console: Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined

well, like @Pointy mentioned in his comment, it basically means that store[ownProps.reduxStoreName].content[ownProps.reduxUid] is undefined. It is not the file which is causing the error, its the specific line. When the code reaches this line and tries to execute it- that store[ownProps.reduxStoreName].content[ownProps.reduxUid] parameter is undefined so it crushes.

We cannot tell you where the error is, we'd need the code of your whole app to follow the execution flow. You have to follow it yourself, and understand why there is not an array in that variable when the code gets there.

As a general idea, try figure out the following:

  1. when and where that variable is initialized?

  2. when and where do you call mapStateToProps?

  3. are you absolutely sure that the code which answers question 1 is executed before the code which answers to question 2? (maybe there is an asynchronous execution problem you didn't think about which causes your code to execute at the wrong order)

  4. if it does- maybe the way you initialize those variables at the beggining is not correct? maybe you use a 3rd party library / function to initialize them, but not actually getting the result you expecting? or maybe you're using it wrong, or parsing the result wrong?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM