小编jus*_*guy的帖子

Parcel 无法使用动态导入解析包

我正在使用 Parcel 来捆绑我的 Javascript 文件。使用本地主机服务器测试构建时一切正常,但在生产中它不喜欢动态导入。

这是我要导入的代码片段:

if (condition) {
    await import('./components/modify_root.js');
  } else {
    await import('./components/index_root.js');
  }
Run Code Online (Sandbox Code Playgroud)

我的确切错误是这样的。错误app.js指向代码片段中的第二行。

在此输入图像描述

The libraries I am using are PreactJS for frontend framework and node-sass for CSS.

dynamic-import preact parceljs

6
推荐指数
0
解决办法
711
查看次数

useEffect 中取消 axios 请求未运行

我正在尝试取消 axios 请求,但只取得了部分成功。当我发出 GET 请求时,我有一个返回 Promise 的函数:

const getCards = (token) => {
  const URL = isDev
    ? "https://cors-anywhere.herokuapp.com/https://privacy.com/api/v1/card"
    : "https://privacy.com/api/v1/card";
  const config = {
    headers: {
      Authorization: `Bearer ${token}`,
    },
    cancelToken: source.token,
  };

  return axios.get(URL, config);
};
Run Code Online (Sandbox Code Playgroud)

我在里面调用这个函数updateCards(),如下所示:

const updateCards = async () => {
  console.log("Updating Cards");

  setCards([]);
  setStarted(true);
  setLoading(true);

  let response = await getCards(token).catch((thrown) => {
    if (axios.isCancel(thrown)) {
      console.error("[UpdateCards]", thrown.message);
    }
  });

  /**
   * response is undefined when we cancel the request on unmount
   */ …
Run Code Online (Sandbox Code Playgroud)

reactjs axios react-hooks

3
推荐指数
1
解决办法
2732
查看次数

标签 统计

axios ×1

dynamic-import ×1

parceljs ×1

preact ×1

react-hooks ×1

reactjs ×1