Unable to enable module in React Native application

I get an error in React Native saying that it cannot resolve the module. He says that a specific folder does not exist, but the path is not exact. This tells me that Directory /Users/user/Desktop/RNApp/app/app/containers does not exist. I have no idea where the second application appears on the way. My directory is as follows

enter image description here

This is how I export my container components to app/containers/index.js

 export RNAppNavigator from './Navigator/RNAppNavigator' export SplashContainer from './Splash/SplashContainer' export AppContainer from './App/AppContainer' 

So, should I be able to import them as import {AppContainer} from '~/containers correctly? I have no problem with other components. Just an AppContainer .

Thanks!

+17
source share
11 answers

react-native start --reset-cache solved the problem. https://github.com/facebook/react-native/issues/1924

+80
source

If you have similar problems with pure components or classes, make sure you use the .js extension instead of the .jsx .

+5
source

Depending on the structure of your folder, try importing this value into index.js:

 import { AppContainer } from './App/AppContainer'; 

If you use named export, that is, if you do:

 export class AppContainer [...] 

If you use the default export, for example:

 export default class AppContainer [...] 

Destruction of the object will fail. You should do instead:

 import AppContainer from './App/AppContainer'; 
+3
source

I lost my desire to live on this error, RN told me that the imported ./Foo file ./Foo not exist when it was there!

Actual main error: not a typo , but actually in another file that ./Foo imported.

Be careful. If you write JSX anywhere (e.g. in ./Bar ):

<Bar>...</Bar>

then you should have:

import * as React from 'react' (or similar)

present in this file ( ./Bar ).

When syntactic sugar (angle brackets) overflows, it naively spits out something like:

React.createComponent(...)

And if React not imported explicitly , this link will be invalid, so the evaluation of this dependent file will subsequently be ignored.

Unfortunately, the result is that ./Foo (as well as ./Bar ) will not be available in your application, and therefore RN talks about useless things like module not found and Indeed, none of these files exist .

Hope this helps.

ps. you can also experience similar misfortune if you have circular dependencies between files! So much fun!

+3
source

Make sure the module is defined in package.json, use npm install and then try using react-native link

+2
source

I had the same problem - fix was babel-preset-react-native-stage-0 instead of babel-preset-react-native .

+1
source

For me, using expo , I just had to restart the expo. ctrl + c and yarn start or yarn start expo start and run on the ios simulator or on your device, depending on what you are testing with.

+1
source

It looks like your error comes from an external index.js file, not from that. You import this file as. / app / containers? because it should just be "./containers"

0
source

I was able to solve this problem by adding the .js file extension. I used Intellij and created a js file, but it did not have a file extension. When I made a refractor, renamed it and changed my component from "List" to "List.js", the native one reacted, but knew how to resolve it.

0
source

Equipment → Erase all content and settings did the work for me (other things did not).

0
source

If the file path is correct, check if one file contains

 import React from './node_modules/react'; 

replace it with

 import React, { Component } from 'react'; 
0
source

Source: https://habr.com/ru/post/1260837/


All Articles