TypeError: fetch is not a function
See original GitHub issuemy code was just working at least 5 hours ago and now is giving me this error
TypeError: fetch is not a function
at Object.<anonymous> (D:\Projects\PaintBot\libs\mc.js:2:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\Projects\PaintBot\commands\about.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
const fetch = import('node-fetch')
const getUUID = async function(un){
let uuid
await fetch(`https://api.mojang.com/users/profiles/minecraft/${un}`)
.then(res=>res.json())
.then(json=>{
try {
uuid = {result: true, uuid: json.id}
} catch {
uuid = {result: false, uuid: null}
}
})
return uuid
}
this code is supposed to just return the result and id but instead, it says fetch isn’t a function, am I doing something wrong?
My Environment
software | version |
---|---|
node-fetch | 3.1.0 |
node | 16.11.1 |
npm | 8.0.0 |
Operating System | Microsoft Windows [Version 10.0.19044.1348] |
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
(CLOSED) TypeError: fetch is not a function, What did I do ...
Try using this style of import: import fetch from 'node-fetch';.
Read more >fetch is not a function · Issue #271 - GitHub
Hello, I'm using fetch from npm packages and when i run the code, it says fetch is not a function. Here is my...
Read more >ReferenceError: fetch is not defined in NodeJs | bobbyhadz
The "ReferenceError: fetch is not defined" occurs when the fetch() method is used in an environment where it's not supported - most commonly...
Read more >fetch fails in page's load function when rendered on the server
It's a weird thing with localhost. Try using 'http://127.0.0.1:1337/api/posts?populate=*' Hopefully the server you are fetching from is allowing ...
Read more >node-fetch - npm
A light-weight module that brings Fetch API to node.js. Latest version: 3.3.0, last published: 2 months ago. Start using node-fetch in your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed! Here is the code:
vscode (typescript) will have a harder time of knowing what the return type is if you assign uuid later like that… it’s better to have a return instead.
few examples if you want to keep import at top: