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=="
}
}
}
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With