【问题标题】:how can i use axios or any others packages in react app which is created by bun cli?我如何在 bun cli 创建的 React 应用程序中使用 axios 或任何其他包?
【发布时间】:2023-02-11 02:55:49
【问题描述】:

我正在尝试使用公理在使用 bun 作为运行时的 React 应用程序中,此应用程序是由包子, 而且我收到此错误,应用程序也没有显示任何内容。

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

我已经使用 bun add axios 命令安装了 Axios 包。

这是我的代码:

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>
  );
}

【问题讨论】:

    标签: reactjs bun


    【解决方案1】:

    您可以使用内置的获取方法:

     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())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多