0

I am trying to use Axios in react app which uses bun as a runtime, this app is created by bun cli, and I am getting this error also app showing nothing.

node_modules.c87bb419727a84b2.bun:7 Uncaught TypeError: Cannot read properties of null (reading 'Symbol(CommonJSTransformed)')
    at Module.c (node_modules.c87bb419727a84b2.bun:7:6663)
    at sr (node_modules.c87bb419727a84b2.bun:7:7075)
    at index.js? [sm]:124:23

I've installed the Axios package using bun add axios command.

here is my code:

import React, { useEffect } from "react";
import { FaBeer } from "react-icons/fa";
import axios from "axios";

export default function UsersList() {
  useEffect(() => {
    const res = axios.get('https://jsonplaceholder.typicode.com/todos/1')
    console.log(res)
  }, [])
  return (
    <div>
      <h3>
        {" "}
        Lets go for a <FaBeer />?{" "}
      </h3>
    </div>
  );
}
rashed01
  • 1
  • 1

1 Answers1

0

In Node 18+, You can use built-in fetch method:

 const customer = await fetch('PATH_TO_API', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: 'SOME NAME',
        email: 'SOME EMAIL'
      })
    }).then(res => res.json())
CACHAC
  • 29
  • 1
  • 2