0

I have just started react-native and trying to create first Hello, world screen but I'm getting below error

ReactNativeJS: ReferenceError: Can't find variable: View

    This error is located at:
        in Unknown
        in RCTView
        in RCTView
        in c

below is my code for App.js

import React, {Fragment,Component} from 'react';

import HelloWorldApp from './components/HelloWorldApp';
import { BrowserRouter as Router, Route } from "react-router-dom"


const App = () => {
  return (
    <Router>
        <div>
          <Route exact path='/' component={HelloWorldApp} />
       </div>
      </Router>
  );
};

export default App;

Below is my code for HelloWorldApp.js

import React, {Component} from 'react';
import {Text, View} from 'react-native';

export default class HelloWorldApp extends Component {
  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
        <Text>Hello, world!</Text>
      </View>
    );
  }
}

I have already import this import {Text, View} from 'react-native'; but still I'm getting error Can't find variable: View

Below are some links that i have already check but it didn't help me to solve my issue

UPDATE

I have tried this Delete and re-install the node modules

Now I'm getting this error

ReactNativeJS: Error: Invariant failed

    This error is located at:
        in l
        in f
        in RCTView
        in RCTView
        in c

can anybody tell me what I'm missing

Can anybody help me to solve this issue

If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.

4
  • If this suddenly happens have you try to close all files and rerun them again? I had situations that fixed by rerunning Commented Sep 24, 2019 at 6:44
  • @behzad thanks for the quick replay let me check this Commented Sep 24, 2019 at 6:44
  • @behzad sorry to say but getting same issue again Commented Sep 24, 2019 at 6:49
  • 1
    Sorry to hear, if this is first time you are running , it may be other things (like not installing dependencies ) but if this happened out of blue that was the only thing that I can think of, few times I had strange error like yours, and when I closed all programs and run them again, it fixed. By the way I hope you find a way to fix soon. Commented Sep 24, 2019 at 6:52

4 Answers 4

0

there is no problem in your code.you should only try react-native init example again and enjoy on another directory

Sign up to request clarification or add additional context in comments.

1 Comment

0

Might be some issues while loading.

Do one thing :

Close the packager and restart the packager along with closing and deleting the app and reinstalling it.

OR

Delete and re-install the node modules

App.js

import React, {Fragment,Component} from 'react';

import HelloWorldApp from './components/HelloWorldApp';
import { BrowserRouter as Router, Route } from "react-router-dom"


const App = () => {
  return (
    <Router>

          <Route exact path='/' component={HelloWorldApp} />

      </Router>
  );
};

export default App;

9 Comments

Thanks i have tried this deleting the app and reinstalling it. but it didn't help me, can you please explain more about this Delete and re-install the node modules solution
delete the node modules folder from root. And then do npm install. Have you tried closing the packager.
Have you tried closing the packager how to close packager
i have tried Delete and re-install the node modules now I'm getting this error ReactNativeJS: Error: Invariant failed This error is located at: check updated question
The terminal which opens or the starter which opens when you run a react project which bundles your file.
|
0

import React,{Component} from 'react'; import {View,Text} from 'react-native';

export default class App extends React.Component {

render(){ return ( Hello world!! ) } }

1.Create new react native project 2.Delete App.js code 3.And paste this code in App.js 4.run.

Comments

-1
import React, { Component } from 'react';
import {View,Text} from 'react-native';

export default class App extends Component {

   render(){
        return(
          <View>
               <Text>Hello world</Text>
          </View>
          )
    }
}
  1. Create new project
  2. Delete App.js code
  3. and paste this code in App.js
  4. run

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.