javascript - 即使我安装了 Fetch 也没有定义
问题描述
我已经使用 npm 安装了 fetch。但我认为它是未定义的。这里的问题在哪里?当我从命令行尝试时,出现错误。
ReferenceError: fetch is not defined
at Object.<anonymous> (C:\Users\mott\Documents\Node.Js.Code\test2.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
fetch("https://api.jsonbin.io/b/5d99501d3d6e417eb7570de2")
.then(function(resp){
return resp.json();
})
.then(function(data){
console.log(data);
}
);
解决方案
推荐阅读
- c# - 将 GROUP BY / MIN DATE 从 SQL 转换为 LINQ
- javascript - 为什么在字符串列表中查找最长公共前缀时出现运行时错误?
- ansible - 评论的 Ansible 条件
- python - 如何使用 linode 服务器在 Ubuntu 上运行 jupyter notebook?
- php - 使用 PHP fsockopen() 建立 IMAP 连接
- api - 将 curl 请求 API 转换为 axios 请求
- django - Django 尝试导入不存在的类
- c# - 如何在 C# 中构建一个将整数计算为 LIFO 集合的函数
- mongodb - 如何使用 Gorm (Mongo) 保存嵌入对象的 Id 字段
- c++ - 为 Mbed BufferedSerial 对象分配的动态内存大小错误