front/react

Only one default export allowed per module 오류, 한 파일에 export default가 여러개 있어서 발생한 오류

jeong_ga 2022. 7. 14. 13:32

수정 전 코드

import axios from "axios";

export default function axiosGetData(url, data) {
  return axios(url, {
    method: "GET",
    data: data,
  })
    .then((res) => res.data)
    .catch((error) => console.log(error));
}

export default function axiosSetData(url, data) {
  return axios(url, {
    method: "POST",
    headers: {
      "content-type": "application/json",
    },
    data: data,
  })
    .then((res) => res.data)
    .catch((error) => console.log(error));
}

기존에 작성하던 방식 그대로 export default function Name 으로 작성하다보니 Only one default export allowed per module 한 개의 default만 esport할 수 있다는 메세지가 나왔고, 아래와 같이 수정하였다.

수정한 코드

import axios from "axios";

function axiosGetData(url, data) {
  return axios(url, {
    method: "GET",
    data: data,
  })
    .then((res) => res.data)
    .catch((error) => console.log(error));
}

function axiosSetData(url, data) {
  return axios(url, {
    method: "POST",
    headers: {
      "content-type": "application/json",
    },
    data: data,
  })
    .then((res) => res.data)
    .catch((error) => console.log(error));
}

export {axiosGetData, axiosSetData}