Reputation: 766
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)
Upvotes: 11
Views: 26140
Reputation: 766
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.
Upvotes: 24
Reputation: 1275
I have solved my issue by the below steps.
Read the error message carefully, the error is node modules path(mentioned as NO: 1 in below image). In my case, I have the "just-cli/" module (Mentioned NO: 2).
search the module (just-cli) you have imported somewhere in your project and just Remove it. The problem will be solved.
Upvotes: -1
Reputation: 8158
None of the answers are really helpful, I found that the problem in my case was that the macros plugin was missing in my babel configuration file.
This is what I had in my babel.config.js
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
};
After adding the macros plugin
module.exports = {
plugins: ["macros"],
presets: ["module:metro-react-native-babel-preset"],
};
If you get this error, most like you are missing a plugin in your babel config.
Upvotes: 1
Reputation: 6958
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.
Upvotes: 10
Reputation: 876
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
Upvotes: 5