首页 > 解决方案 > 即使我安装了 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);
}
);

标签: javascriptnode.js

解决方案


推荐阅读