afnan
afnan

Reputation: 13

Error While Importing Axios: Uncaught SyntaxError: Cannot use import statement outside a module

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

Upvotes: 0

Views: 1495

Answers (1)

Ghulam Ghous
Ghulam Ghous

Reputation: 21

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

Upvotes: 1

Related Questions