Unable to resolve module `axios`
See original GitHub issueSummary
I’m trying to implement Axios into a React Native project. But the bundler refuse to pack, saying it’s not found. I’m not sure if it is a React Native bug (cause i’ve tried on fresh project and it worked) or a Axios one.
I’ve imported that way:
import axios from 'axios';
and it produces:
error: bundling failed: Error: Unable to resolve module
axios
from/Users/bernard/Dev/Reach/application/App.js
: Moduleaxios
does not exist in the Haste module map or in these directories: /Users/bernard/Dev/Reach/application/node_modulesThis might be related to https://github.com/facebook/react-native/issues/4968 To resolve try the following:
- Clear watchman watches:
watchman watch-del-all
.- Delete the
node_modules
folder:rm -rf node_modules && npm install
.- Reset Metro Bundler cache:
rm -rf /tmp/metro-bundler-cache-*
ornpm start -- --reset-cache
.- Remove haste cache:
rm -rf /tmp/haste-map-react-native-packager-*
. at ModuleResolver.resolveDependency (/Users/bernard/Dev/Reach/application/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:183:15) at ResolutionRequest.resolveDependency (/Users/bernard/Dev/Reach/application/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18) at DependencyGraph.resolveDependency (/Users/bernard/Dev/Reach/application/node_modules/metro/src/node-haste/DependencyGraph.js:283:16) at Object.resolve (/Users/bernard/Dev/Reach/application/node_modules/metro/src/lib/transformHelpers.js:261:42) at dependencies.map.result (/Users/bernard/Dev/Reach/application/node_modules/metro/src/DeltaBundler/traverseDependencies.js:399:31) at Array.map (<anonymous>) at resolveDependencies (/Users/bernard/Dev/Reach/application/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:18) at /Users/bernard/Dev/Reach/application/node_modules/metro/src/DeltaBundler/traverseDependencies.js:269:33 at Generator.next (<anonymous>) at asyncGeneratorStep (/Users/bernard/Dev/Reach/application/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)
I’ve tried a lot of things:
- Doing all the command in error message => same bug
- Removing node_modules and all lock files then reinstalling => same bug
- Switching from/to yarn/npm => same bug
- Importing directly axios/dist/index => same bug.
I’m kinda desperate and i’m requiring your help…
Context
- axios version: 0.19.0
- Environment: node v10.15.3, mac os x 10.14.5, react 16.8.3, react native 0.59.9
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:7
Top Results From Across the Web
16 - Stack Overflow
The error message means that the axios package is missng and needs to be installed. Run below command in your project ...
Read more >Module not found: Can't resolve 'axios' in React | bobbyhadz
To solve the error "Module not found: Error: Can't resolve 'axios'", make sure to install the axios package by opening your terminal in...
Read more >failed to resolve module specifier "axios". relative references ...
I get Uncaught TypeError: Failed to resolve module specifier "axios". Relative references must start with either "/", "./", or ".
Read more >axios - npm
Promise based HTTP client for the browser and node.js. Latest version: 1.2.1, last published: 23 days ago. Start using axios in your project ......
Read more >module not found: error: can't resolve 'axios' - Code Grepper
module not found: error: can't resolve 'axios'. Add Answer | View In TPC Matrix. Technical Problem Cluster First Answered On December 19, 2020...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had this config in my
metro.config.js
:It turns out
axios
matches the regex/ios\/.*/
so the lib was being ignored by the metro bundler. I changed it to/\/ios\/.*/
and it worked:I’m also getting the same error, tried configuring the
metro.config.js
withextraNodeModules
:paths tried:
'./node_modules/axios/index'
'./node_modules/axios/lib/axios'
'./node_modules/axios'
'./node_modules/axios/dist/axios'
Nothing works… 🤷♂️