TypeError: Cannot read properties of undefined
A script expected some information and got nothing. It is the same class of problem as the most common Lua error.
Do this first
Note which script it names; the fix is in that script's code.
What it means
JavaScript's version of "attempt to index a nil value". Something was accessed on a value that is undefined or null. The message names the property, which tells you which access failed but not which value was missing.
What causes it
Ordered by how often it is the answer.
- 1
A player object that does not exist
A server script looking up a player who has disconnected.
- 2
An await that was forgotten
const rows = db.query(...)withoutawaitgives a Promise, and reading a field off it is undefined. - 3
A destructure of a missing object
const { id } = payloadwhenpayloadnever arrived. - 4
An event payload the client did not send
Same class of bug as the Lua version, on the other runtime.
- 5
An export from a resource that is not started
exports['x'].ywhere the export object is undefined.
How to tell which one is yours
console.log(typeof thing, thing)
directly above the failing line. In FXServer this prints to the server console like any other output.
Where to look
The named line, then the assignment that produced the undefined value.
How to fix it
Use optional chaining and defaults at the boundary:
const player = getPlayer(src)
if (!player) return
const amount = payload?.amount ?? 0
const rows = await db.query('SELECT ...')Still stuck on your own code?
This page is what this error usually means. Paste your console into Server Fixer and it will rank everything in it and tell you what to do first, and if you would rather not touch it, ORBIE can repair the script and hand the resource back ready to drop in.
bug_reportOpen Server Fixer