简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM