Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript require method is not finding axios module

I am creating a chrome extension for gmail. I have installed axios using "npm install axios" and that has created a node_modules folder with the module included. I then tried to include the module in my extension.js file but gives "cannot find module 'axios'" error. The axios documentation says "In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require() use the following approach:

 const axios = require('axios').default;

So i placed it in my extension.js

const axios = require('axios').default;

The axios location leads to the index.d.ts file. I am not sure why it does not go to the index.js where the

module.exports = require('./lib/axios');

is located.

package-lock.json

{
  "requires": true,
  "lockfileVersion": 1,
  "dependencies": {
    "axios": {
      "version": "0.21.1",
      "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
      "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
      "requires": {
        "follow-redirects": "^1.10.0"
      }
    },
    "follow-redirects": {
      "version": "1.13.3",
      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
      "integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
    }
  }
}
like image 707
Jimmy Avatar asked Oct 24 '25 20:10

Jimmy


1 Answers

Try: npm install axios

Then:

import axios from 'axios'; // ES6 module syntax

// ... or using CommonJS syntax:

const axios = require('axios'); // CommonJS syntax

Note: If you still facing same issue please visit following links:

  1. [ts] cannot find module 'axios' &
  2. https://github.com/SimulatedGREG/electron-vue/issues/940
like image 159
Rashed Rahat Avatar answered Oct 27 '25 10:10

Rashed Rahat