导入 Axios 时出错:未捕获的语法错误:无法在模块外使用导入语句

时间:2021-01-29 08:11:14

标签: javascript node.js axios

导入 Axios 时遇到错误

<块引用>

未捕获的语法错误:不能在模块外使用导入语句

我是这样导入 Axios 的:

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 个答案:

答案 0 :(得分:0)

你在哪里使用这个语句?如果你在后端使用它,那么你应该使用

const axios = require('axios');

如果你是在前端获得它,那么你可能没有安装包 axios。安装它运行

npm i axios