使用 React 导出异步函数,(在 运行 npm build 时出错)

Exporting async functions with React, (getting error when running npm build)

我在我的 React 项目中重新使用异步函数,我有一个名为 apiRequest.js 的文件,它看起来像这样:

const axios = require('axios');
const serverURL = "http://localhost:8080"

getInfo = async function ({email}) {
  try {
      return await axios.post(serverURL, { email: email })
    } catch (error) {
      console.error(error)
    }
}

module.exports = {
    getInfo
};

我的组件尝试加载这样的函数,在开发模式下工作

import { getInfo } from "./../../util/apiRequest.js";

当我 运行 npm run build 时,我得到这个错误:

Attempted import error: 'getInfo' is not exported from './../../util/apiRequest.js'.

导出此函数时我做错了什么?

我已经尝试删除 const 和删除粗箭头 => 但仍然得到相同的结果。

使用 ES6 模块导入和导出

import axios from 'axios'

export const getInfo = async() => {

}