Noname
Noname

Reputation: 83

Problem with "react-native init" template app: Unable to resolve module `./index` from react-native/scripts

After doing averything according to https://facebook.github.io/react-native/docs/getting-started , with an android studio emulator, and creating a template app with "react-native init myApp", i get this error:

Error: Unable to resolve module `./index` from `C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\react-native\scripts/.`: The module `./index` could not be found from `C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\react-native\scripts/.`. Indeed, none of these files exist:
  * `C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\react-native\scripts\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
  * `C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\react-native\scripts\index\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
    at ModuleResolver.resolveDependency (C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\node-haste\DependencyGraph.js:283:16)
    at C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\lib\transformHelpers.js:261:42
    at Server.<anonymous> (C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\Server.js:1038:41)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\Server.js:99:24)
    at _next (C:\Users\Oleg\Desktop\progStuff\SSFD2\node_modules\metro\src\Server.js:119:9)
::ffff:127.0.0.1 - - [24/Mar/2019:08:18:16 +0000] "GET /index.delta?platform=android&dev=true&minify=false HTTP/1.1" 500 - "-" "okhttp/3.12.1"

Out of all the things i tried, including re-initializing the project, re-checking that i have everything installed and up-to-date, reinstalling some stuff, the only one that worked was using 0.58.6 version of react-native, it works fine. But i don't like that solution and want to use the latest version.

Upvotes: 2

Views: 1704

Answers (4)

jim1029
jim1029

Reputation: 26

This is a issue by react-native and has just been fixed in a pending release. Run react-native start is one tab and run react-native run-android in another tab can fix it temporary (or downgrade to [email protected]).

https://github.com/facebook/react-native/issues/24112

Looks like this issue is only for the automatically launched packager as part of react-native run-android - if you run react-native start separately before run-android you should be good for now.

Update:

react-native v0.59.2 fixed this issue on iOS but still not working for android yet. Now you need to run react-native start --reset-cache and react-native run-android in two terminals.

Update2:

https://github.com/facebook/react-native/issues/24112#issuecomment-477069406

Follow this link to modify launchPackager.bat seems to the temporary workaround for Windows users.

Upvotes: 1

Ankush Rishi
Ankush Rishi

Reputation: 3150

Clean your cache:

rm -rf $TMPDIR/react-*; rm -rf $TMPDIR/haste-*; rm -rf $TMPDIR/metro-*; watchman watch-del-all

Restart packager:

react-native start

Now run your app:

react-native run-android or react-native run-ios

Upvotes: 0

Pramod
Pramod

Reputation: 1940

Use the following:

react-native start --reset-cache

Upvotes: 1

RAHUL JOSHI
RAHUL JOSHI

Reputation: 354

Error is stating that, it is not able to find the module react-native dependency from the node_modules. You should probably

try deleting the node modules

and run npm install again.

Upvotes: 0

Related Questions