Fix ESX Is Nil / getSharedObject Errors
Fix ESX is nil, attempt to index a nil value and no such export getSharedObject in ESX Legacy, with verified imports.lua examples and resource load-order checks.
If your console reports ESX is nil, attempt to index a nil value (global 'ESX') or No such export getSharedObject, inspect the resource import and whether es_extended is running.
Recommended fix — import ESX in your manifest
fx_version 'cerulean'
game 'gta5'
shared_scripts {
'@es_extended/imports.lua',
'config.lua',
}
client_script 'client.lua'
server_script 'server.lua'
dependency 'es_extended'The import makes ESX available on both sides, but server-only APIs must still run on the server. The import must be loaded before your resource's own files.
Alternatively, retrieve the export after the framework loads:
local ESX = exports['es_extended']:getSharedObject()Has esx:getSharedObject really been removed?
No. The maintained ESX Legacy 1.16.4 source still registers this event for backward compatibility:
local ESX
TriggerEvent('esx:getSharedObject', function(object)
ESX = object
end)It is a legacy pattern. Prefer @es_extended/imports.lua or exports['es_extended']:getSharedObject() for new code, but do not claim that the old event no longer exists.
Troubleshoot the exact message
attempt to index a nil value (global 'ESX')
- Check the
shared_scriptsentry and its order. - Add
dependency 'es_extended'infxmanifest.lua. - Confirm that
es_extendedstarted without errors. - Search for a conflicting or uninitialized
local ESXvariable.
No such export getSharedObject in resource es_extended
Check the es_extended folder name, whether its fxmanifest.lua is at the correct level and whether the core actually started. The export exists in the maintained source; startup failures can prevent it becoming available.
Couldn't load resource es_extended
Look for the first server error rather than changing the export call. Dependencies such as esx_lib and oxmysql may be missing. See ESX troubleshooting.
ESX.GetPlayerFromId is nil
ESX.GetPlayerFromId is a server-side function. Use the server API on the server and the client API on the client.
Related
Frequently asked questions
Independent documentation
Last updated on
Troubleshooting ESX Legacy
Fix common ESX Legacy errors - ESX is nil, oxmysql connection failures, es_extended not starting, OneSync kicks, players stuck on loading and multicharacter problems.
Fix ESX Multicharacter Problems
Diagnose ESX multicharacter not working, stuck character selection, blank NUI, failed relog and missing characters using current esx_multicharacter source.