-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Flatlist render error: Cannot read property 'getItem' of undefined #36828
Comments
We would need a reproducer to investigate this further sadly. |
|
Got the same error, only on android, any solution? |
not yet, been searching for a week already |
Hello, thanks for yout reply. Here I have created the sample repo which is exactly same as my project, but it is working on new project. LINK: github repository. Thanks |
This issue is not actionable without a repro or at least a callstack. |
TypeError: Cannot read property 'getItem' of undefined This error is located at: |
Maybe this will help solve the problem |
So, the undefined bit here looks to be "this.props", which is derived directly from the input of the components constructor. react-native/Libraries/Lists/FlatList.js Line 420 in 030ab8e
To continue figuring this out, I would attach a debugger to the FlatList constructor and follow the values. It seems very unlikely that this issue is in FlatList, but there could maybe be other environment factors. |
<FlatList data={[]} renderItem={() => <></>} /> I tried using without the extra parameters in App.ts, but the problem remained. The error is only on Android, everything is fine with iOS. |
I found the problem. After removing this code from babel.config.js and removing @babel/plugin-proposal-private-methods, everything is fine. |
Yeah, I have tries this previously as well, but didnt help .... ((( |
Thanks to @chizhkov422 I have checked my
which made it work again. Thanks one more time |
good job |
Since this is a common enough plugin (as is |
yes it's working when I remove I got another error while jest-runner/build/index.js: Class private methods are not enabled. Please add Does anyone know how this will fix? |
@infoani92 instead of removing @babel/plugin-proposal-private-methods you could install to devDependancies and add in babel plugins before @babel/plugin-proposal-private-methods (it is important) this plugin: @babel/plugin-transform-flow-strip-types. It should help |
Thank you @chizhkov422 you saved my time |
Im still having the same issue. Adding ive removed the suggested parts of my babel.config.js above but the error still persits. Completely stuck! |
Im not sure if I'm following you, you mean to do this right? Delete the following lines from '@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-private-methods', and then run yarn add @babel/plugin-proposal-private-methods --dev
yarn add @babel/plugin-transform-flow-strip-types --dev |
nothing to add just remove
On Tue, Jun 13, 2023 at 1:46 AM mattgle.eth ***@***.***> wrote:
@infoani92 <https://github.com/infoani92> instead of removing
@babel/plugin-proposal-private-methods you could install to devDependancies
and add in babel plugins before @babel/plugin-proposal-private-methods (it
is important) this plugin: @babel/plugin-transform-flow-strip-types. It
should help
Im not sure if I'm following you, you mean to do this right?
Delete
***@***.***/plugin-proposal-class-properties',
***@***.***/plugin-proposal-private-methods',
from babel.config.js
and then run
yarn add @babel/plugin-proposal-private-methods --dev
yarn add @babel/plugin-transform-flow-strip-types --dev
—
Reply to this email directly, view it on GitHub
<#36828 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4ZHHHF3NOAORINHVDDNFTXK52I7ANCNFSM6AAAAAAWVA6QMI>
.
You are receiving this because you commented.Message ID:
***@***.***>
--
*Thanks*
*Allu Lavaraju*
*Sr. Software Engineer*
*9912661587*
|
Guys, I'm also getting this same issue in the Flatlist from today morning. Here is what my rolled back version of babel.config.js looks like:
Here is what my package.json looks like:
Please note that, this error was not there before when I committed these changes. Can anyone please help me out. |
Guys, I solved this issue. |
This shouldn't have been closed. The bug is still there. I agree with 0xFadedd: The local object this.props is not initialized. The fix is simply to initialize it as 0xFadedd lucidly explained last year. |
This is another comment with the same simple fix as proposed by 0xFadedd : |
This worked for me and didn't break the tests |
I have the same issue here, not resolved by others suggestions |
This fixed my problem after trying many of the other suggestions. Thank you |
Thank you. This worked for me too in expo. |
Summary: This solves [ENG-7635](https://linear.app/comm/issue/ENG-7635/cannot-read-property-getitem-of-undefined), at least temporarily. It looks like it's [this GitHub issue](facebook/react-native#36828), first introduced by [this change](d543b13#diff-6cbb99cac6ea458360d1a029240d3d962e43c86756958d30bfe0434166be073a). People on the GitHub issue have several suggestions: 1. This change 2. Removing `@babel/plugin-transform-private-methods`, which we could consider if we remove the private method uses in the transitive dependency that necessitates its introduction initially 3. Adding a babel plugin somewhere that strips Flow types. I'll consider this one as I continue investigating Test Plan: Confirm that the issue goes away after resetting the Metro cache (`yarn dev -c`) and refreshing the app Reviewers: ginsu, will, atul Subscribers:
Summary: This solves [ENG-7635](https://linear.app/comm/issue/ENG-7635/cannot-read-property-getitem-of-undefined), at least temporarily. It looks like it's [this GitHub issue](facebook/react-native#36828), first introduced by [this change](d543b13#diff-6cbb99cac6ea458360d1a029240d3d962e43c86756958d30bfe0434166be073a). People on the GitHub issue have several suggestions: 1. This change 2. Removing `@babel/plugin-transform-private-methods`, which we could consider if we remove the private method uses in the transitive dependency that necessitates its introduction initially 3. Adding a babel plugin somewhere that strips Flow types. I'll consider this one as I continue investigating Test Plan: Confirm that the issue goes away after resetting the Metro cache (`yarn dev -c`) and refreshing the app Reviewers: ginsu, will, atul Subscribers: tomek Differential Revision: https://phab.comm.dev/D11527
Summary: This solves [ENG-7635](https://linear.app/comm/issue/ENG-7635/cannot-read-property-getitem-of-undefined), at least temporarily. It looks like it's [this GitHub issue](facebook/react-native#36828), first introduced by [this change](d543b13#diff-6cbb99cac6ea458360d1a029240d3d962e43c86756958d30bfe0434166be073a). People on the GitHub issue have several suggestions: 1. This change 2. Removing `@babel/plugin-transform-private-methods`, which we could consider if we remove the private method uses in the transitive dependency that necessitates its introduction initially 3. Adding a babel plugin somewhere that strips Flow types. I'll consider this one as I continue investigating Test Plan: Confirm that the issue goes away after resetting the Metro cache (`yarn dev -c`) and refreshing the app Reviewers: ginsu, will, atul Reviewed By: ginsu Subscribers: tomek Differential Revision: https://phab.comm.dev/D11527
Broo just thank you, you just save me you absolute genius person. Thank you brother have a great day. |
thanks, man, I remove these lines of my babel.config.js: ["@babel/plugin-transform-private-methods", { loose: true }], |
By removing @babel/plugin-transform-private-methods, I solved this bug, but it created another bug when I ran test |
needed this line in my babel config for msw to work but removing it made storybooks work lol. Thanks for the tip @HoaiHuynh! |
It seems like removing @babel/plugin-transform-private-methods solved my original issue with React Native Windows, but created a new bug when running tests. |
add this line into the FlatList.js file and not do npm install after this because it will remove the changes you have done in the file. Like this - constructor(props: Props) { |
Description
I have been working on project which has several flatlists, which are causing problem suddenly. All flatlists that I have shows same issue dispite they were working previously. To add, auto refreshing also stopped working I dont know they are related to each other or not.
React Native Version
0.71.3
Output of
npx react-native info
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i3-10105 CPU @ 3.70GHz
Memory: 5.21 GB / 15.87 GB
Binaries:
Node: 18.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 28, 31, 33
Build Tools: 28.0.3, 30.0.3, 31.0.0, 33.0.0
System Images: android-28 | Google APIs Intel x86 Atom, android-31 | Intel x86 Atom_64, android-31 | Google Play Intel x86 Atom_64, android-33 | Google APIs Intel x86_64 Atom
Android NDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: AI-213.7172.25.2113.9123335
Visual Studio: Not Found
Languages:
Java: 11.0.18
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.3 => 0.71.3
react-native-windows: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Steps to reproduce:
Open the project and navigate to the screen where the flatlists are being used.
Observe that all the flatlists are not rendering and showing an error.
Check the console for any error messages related to the flatlists.
Look for the specific error message "Cannot read property 'getItem' of undefined".
Verify that this error is being displayed for all the flatlists on the screen.
Check if the code for the flatlists has been modified recently or if any libraries have been updated.
Verify that the data source for the flatlists is correctly defined and passed as props.
Make sure that the flatlist component is imported and rendered properly in the code.
Check if any other component or library is conflicting with the flatlists.
Provide any additional information that might be helpful for developers to identify and fix the issue.
Expected outcome:
The flatlists should render without any errors.
Actual outcome:
The flatlists are not rendering and showing the error message "Cannot read property 'getItem' of undefined".
Snack, code example, screenshot, or link to a repository
// CODE IS GIVEN BELOW IS EXAMPLE WHICH WORKS ON BRAND NEW PROJECT BUT NOT IN THE CURRENTLY USED ONE
import React, {useState} from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
Platform,
View,
FlatList,
} from 'react-native';
import {COLORS} from '../constants/theme';
const DATA = [
{id: '1', title: 'Item 1'},
{id: '2', title: 'Item 2'},
{id: '3', title: 'Item 3'},
{id: '4', title: 'Item 4'},
{id: '5', title: 'Item 5'},
{id: '6', title: 'Item 6'},
{id: '7', title: 'Item 7'},
];
const Item = ({title}) => (
{title}
);
const Settings = () => {
const [selectedId, setSelectedId] = useState(null);
const renderItem = ({item}) => ;
return (
<FlatList
horizontal
showsHorizontalScrollIndicator={false}
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
extraData={selectedId}
/>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 50,
},
item: {
backgroundColor: COLORS.primary,
padding: 5,
borderRadius: 20,
marginHorizontal: 5,
height: 50,
justifyContent: 'center',
alignItems: 'center',
},
title: {
fontSize: 22,
color: 'white',
},
});
export default Settings;
The text was updated successfully, but these errors were encountered: