为什么 fetch 在后端服务器的所有分支上对我来说停止工作?

问题描述 投票:0回答:1

重构后,在单独的分支上,fetch 在任何分支上都不再有效。其他一切都按预期工作。错误:

...server/KE/utils.ts:44
const response = await fetch(
                 ^
ReferenceError: fetch is not defined

重构将逻辑从 KE/router.ts 移动到 KE/utils.ts 中的函数。
fetch 存在于 lib.dom.d.ts.
有一个朋友的朋友运行代码,他们能够毫无问题地调用 fetch。

修复尝试

  • 我将功能从 KE/utils.ts 逻辑移回 KE/router.ts。
  • 将所有导入从 KE/router 复制到 KE/utils。
  • 已安装节点获取。
    Import fetch from 'node-fetch'
    。停止编译,因为它混淆了 express 的数据类型。
  • 检查以前工作的分支。
  • 用 npm 重新安装所有包。
  • 使用
    curl -qL https://www.npmjs.com/install.sh | sudo sh
  • 重新安装 npm

版本

  • npm - 9.6.2
  • 快递 - 4.18.2
  • vue-3.2.47
  • 打字稿 - 4.5.5
  • nodemon-2.0.21
node.js typescript vue.js express nodemon
1个回答
0
投票

后端在 Node 上运行。将节点更新到 >= 18.0.0 的版本以进行修复。 来源.

使用 nvm 安装最新节点:

nvm install node

来源:@Mike'Pomax'Kamermans

© www.soinside.com 2019 - 2024. All rights reserved.