0
votes

While importing Axios I am facing an error

Uncaught SyntaxError: Cannot use import statement outside a module

I am importing Axios like this:

import axios from 'axios'

this image shows my javascript file strucure where i hava imported axios which i installed through npm i axios

this is how i import axios in main js file that is shown above

this is my project header ,where i have included my js file

1
try const axios = require('axios').default; - Nnay
@NotABot i am using it in the front end , main.js file - afnan
@afnan Please check the link I mentioned in the previous comment, you will get some help from there - Not A Bot
we just don't know enough. is your main.js file an ES module? are you working within a framework that compiles and bundles your code? - Nnay

1 Answers

0
votes

Where are you using this statement? If you are you using it on backend then you should use

const axios = require('axios');

if you are getting it on frontend then you may not have installed the package axios. To install it run

npm i axios