avriis
avriis

Reputation: 1681

Can't find variable: Component in react native

I'm building a simple app with react native using among other things Expo. After an update of react, expo, react-native from a previous version, I get an error I cannot seem to get rid of (see picture). I have looked in index.js, MainNavigator.js, LoginNavigator.js to ensure that I have import React, {Component } from 'react'; in the preamble, but the problem persists. Can anyone guide me in a direction to help solve this problem?

enter image description here

Also tried:

Excerpt from package.json: Versions:

Upvotes: 3

Views: 22348

Answers (6)

Rudresh Oza
Rudresh Oza

Reputation: 83

see that if you are use classes in react-native then you should add {component} from react as given below.

import {component} from React;

Upvotes: -2

Anayo Oleru
Anayo Oleru

Reputation: 516

I've experienced this before, after searching all thorough the codebase, finally, I found it where I couldn't believe it'll be App.js file. So if you've tried restarting your bundler and running npm start --reset-cache or yarn start --reset-cache, and the issue still persist, check all your files and components you worked on, you imported React without importing Component, for instance:

import React, {Component} from 'react';

Upvotes: 0

Keshav Gera
Keshav Gera

Reputation: 11244

npm start -- --reset-cache

and Invailidate Cache and Restart

Upvotes: 1

Satish
Satish

Reputation: 537

I have fixed this issue in my project. First add react-native to your packages.

yarn add react-native

Then changing below line:

OLD

import React from 'react';

NEW

import React, {Component} from 'react';

Upvotes: 3

Choi
Choi

Reputation: 523

My solution was changing this line as:
From

import React from 'react';

To

import React, {Component} from 'react';

Upvotes: 14

Matt Aft
Matt Aft

Reputation: 8936

When upgrading expo versions, make sure you follow their upgrading guide and do it one version at a time: https://blog.expo.io/expo-sdk-v25-0-0-is-now-available-714d10a8c3f7

Upvotes: 3

Related Questions