[英]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() => {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.