All articles
JavaScriptAI CodeHallucinations7 min read

The Complete List of Hallucinated JavaScript APIs (2026)

VG
VibeGuard Team

AI coding assistants are trained on millions of code examples across dozens of languages. The result? They sometimes blend APIs from different languages or invent methods that seem logical but don't actually exist. We call these "hallucinated APIs."

We've catalogued every hallucinated JavaScript API pattern we've seen across thousands of scans on VibeGuard. This is the definitive list.


Fetch API Hallucinations

The Fetch API is the #1 source of hallucinated methods. AI models frequently confuse it with Axios or other HTTP libraries.

// ❌ Hallucinated — fetch is not axios
await fetch.get('/api/data')
await fetch.post('/api/data', body)
await fetch.put('/api/data', body)
await fetch.delete('/api/data')

// ✅ Correct
await fetch('/api/data')
await fetch('/api/data', { method: 'POST', body: JSON.stringify(body) })
await fetch('/api/data', { method: 'PUT', body: JSON.stringify(body) })
await fetch('/api/data', { method: 'DELETE' })

Why it happens: Axios has .get(), .post(), etc. AI models see these patterns millions of times and sometimes apply them to fetch.


Array Method Hallucinations

// ❌ Hallucinated
myArray.flatten()          // Should be .flat()
myArray.unique()           // Use [...new Set(myArray)]
myArray.compact()          // Lodash method, not native
myArray.first()            // Use myArray[0] or .at(0)
myArray.last()             // Use myArray.at(-1)
myArray.isEmpty()          // Use myArray.length === 0
myArray.contains(item)     // Should be .includes(item)
myArray.collect()          // Ruby/Kotlin, not JS
myArray.each(fn)           // jQuery, use .forEach()
myArray.pluck('name')      // Underscore/Lodash, not native
myArray.where({ active: true })  // Backbone.js, not native
myArray.sortBy('name')     // Lodash, use .sort((a,b) => ...)

// ✅ Correct alternatives
myArray.flat()
[...new Set(myArray)]
myArray.filter(Boolean)
myArray[0]
myArray.at(-1)
myArray.length === 0
myArray.includes(item)
myArray.map(fn)
myArray.forEach(fn)
myArray.map(item => item.name)
myArray.filter(item => item.active)
myArray.sort((a, b) => a.name.localeCompare(b.name))

Why it happens: Many of these methods exist in other languages (Ruby, Python, Kotlin) or popular libraries (Lodash, jQuery). The AI blends them together.


String Method Hallucinations

// ❌ Hallucinated
myString.format('Hello %s', name)    // Python's str.format()
myString.capitalize()                 // Ruby/Python, not native JS
myString.center(20)                   // Python
myString.strip()                      // Python, use .trim()
myString.lstrip()                     // Python, use .trimStart()
myString.rstrip()                     // Python, use .trimEnd()
myString.isEmpty()                    // Use myString.length === 0
myString.contains('sub')             // Use .includes('sub')
myString.toTitleCase()               // Not native
myString.reverse()                    // Strings don't have .reverse()

// ✅ Correct
`Template literal: Hello ${name}`
myString.charAt(0).toUpperCase() + myString.slice(1)
myString.padStart(20)
myString.trim()
myString.trimStart()
myString.trimEnd()
myString.length === 0
myString.includes('sub')
// Custom: myString.replace(/\b\w/g, c => c.toUpperCase())
myString.split('').reverse().join('')

Promise Hallucinations

// ❌ Hallucinated
promise.done()              // jQuery Deferred, not native
promise.fail(handler)       // jQuery Deferred
promise.always(handler)     // jQuery, use .finally()
promise.success(handler)    // Not a thing
promise.error(handler)      // Not a thing
Promise.delay(1000)         // Bluebird, not native
Promise.map(arr, fn)        // Bluebird, not native
Promise.each(arr, fn)       // Bluebird

// ✅ Correct
promise.then(result => { /* done */ })
promise.catch(handler)
promise.finally(handler)
promise.then(handler)
promise.catch(handler)
await new Promise(r => setTimeout(r, 1000))
await Promise.all(arr.map(fn))
for (const item of arr) { await fn(item) }

Object Hallucinations

// ❌ Hallucinated
Object.merge(target, source)      // Use Object.assign() or spread
Object.isEmpty(obj)               // Not native
Object.size(obj)                  // Use Object.keys(obj).length
Object.each(obj, fn)              // jQuery/Lodash
Object.map(obj, fn)               // Not native on Object
JSON.parseAsync(str)              // Doesn't exist

// ✅ Correct
Object.assign(target, source)     // or { ...target, ...source }
Object.keys(obj).length === 0
Object.keys(obj).length
Object.entries(obj).forEach(([k, v]) => fn(k, v))
Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, fn(v)]))
JSON.parse(str)

Node.js / fs Hallucinations

// ❌ Hallucinated
fs.readFileAsync(path)            // Use fs.promises.readFile()
fs.writeFileAsync(path, data)     // Use fs.promises.writeFile()
fs.existsAsync(path)              // Use fs.promises.access()
fs.readJSON(path)                 // Not native (fs-extra has this)
require.async('module')           // Not a thing
import.meta.require('module')    // Not standard

// ✅ Correct
await fs.promises.readFile(path, 'utf-8')
await fs.promises.writeFile(path, data)
await fs.promises.access(path).then(() => true).catch(() => false)
JSON.parse(await fs.promises.readFile(path, 'utf-8'))

Why This Matters

Every hallucinated API is a runtime crash waiting to happen. Your code compiles. Your types might even check out (especially if any is involved). But the moment a user hits that code path — TypeError: fetch.get is not a function.

These bugs are particularly insidious because: 1. They look correct to humans doing a quick review 2. They pass linters and often TypeScript 3. They only surface at runtime, often in production 4. They're scattered across an entire AI-generated codebase


How to Catch Them Automatically

VibeGuard maintains a comprehensive database of hallucinated API patterns and scans your code against it. Every method call is checked against the actual JavaScript/TypeScript standard library and popular frameworks.

Paste your code → get a report with exact line numbers → see what's real and what's hallucinated.

→ [Scan your code free at vibeg.io](https://vibeg.io/scan)


*This list is updated regularly as we discover new hallucination patterns. Last updated: March 2026.*

Free to start

Scan your code for these issues now

VibeGuard catches all the vulnerabilities described in this article — automatically, in under 3 seconds.

Scan Your Code Free