Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unable to resolve module path" in React Native

Tags:

react-native

After adding a new dependency, I get the error message "Unable to resolve module path" in a red screen in my React Native app. I've tried clearing the cache as the screen instructs.

(question is brief as I'm answering it myself)

like image 657
danharper Avatar asked Jan 06 '17 17:01

danharper


3 Answers

The error message:

Unable to resolve module path

Should really be:

Unable to resolve module "path"

path is the name of the module it can't load! I was reading the error message as "can't resolve a path to the module".

So the root cause is, the file it lists in the error message is importing the native Node module path, which isn't available on React Native.

The solution is to npm install -D path, which is a replica implementation.

like image 89
danharper Avatar answered Nov 03 '22 06:11

danharper


Any imports from @babel/core package is causing this error.

Some code editors are inserting the import line automatically.

For example, import { types } from '@babel/core' is inserted by Visual Studio Code when you enter types.

If you remove the imports from @babel/core in the codes, it will be fixed.

like image 28
Colin Wang Avatar answered Nov 03 '22 04:11

Colin Wang


Quote from chronikum on react-native github issues for future readers

Just check if you somewhere accidentally imported something from @babel/core.

Here is the original link

https://github.com/facebook/react-native/issues/27522#issuecomment-568306279

like image 5
Çağdaş Tunca Avatar answered Nov 03 '22 05:11

Çağdaş Tunca