FiveM exports in Lua: exports('name', fn) and 'No such export'

How to define and call exports in FiveM Lua, the fxmanifest exports and server_exports styles, and how to fix 'No such export' errors caused by start order or the wrong side.

A script calls another one and the console answers:

text
No such export getCount in resource my_inventory

This article shows how exports are defined and called in Lua, the two ways to declare them, and the usual reasons that error appears.

Defining an export

An export lets one resource offer a function to the others. The simple way is the exports function inside a script:

lua
-- my_inventory/server/main.lua
local function getCount(source, item)
    -- ...
    return 5
end

exports('getCount', getCount)

You can also pass the function inline:

lua
exports('getCount', function(source, item)
    return 5
end)

That is all. There is nothing to add to fxmanifest.lua, and the export exists on whichever side the script runs: put it in a server script and it is a server export, put it in a client script and it is a client export.

The manifest style

Older resources declare exports in fxmanifest.lua and define a plain global function with the same name:

lua
-- fxmanifest.lua
fx_version 'cerulean'
game 'gta5'

server_exports { 'getCount' }
exports { 'getOwnedCount' }
lua
-- server script
function getCount(source, item)
    return 5
end
  • exports { … } lists client exports.
  • server_exports { … } lists server exports.

This still works, and many ESX and QBCore resources use it. The two styles do not conflict, so a resource can mix them. For new code, exports('name', fn) is simpler because the function and the export live together, and you cannot forget a line in the manifest. Remember that fxmanifest.lua is the current manifest filename: see fxmanifest vs __resource.lua.

Calling an export

From any other resource on the same side:

lua
local count = exports['my_inventory']:getCount(source, 'water')

The dot and colon versions are the same thing, as long as the name is a valid Lua identifier:

lua
local count = exports.my_inventory:getCount(source, 'water')

Use the bracket form when the resource name has a dash, such as exports['qb-core']:GetCoreObject(). The call is synchronous: it returns the value of the function, and it can yield if the function waits.

Tip: arguments and return values travel between resources, so tables are copied. Changing a table you got from an export does not change the other resource's own data. Functions inside a returned table still work, as they call back into the owner.

Why you get "No such export"

text
No such export getCount in resource my_inventory

Check these, in this order:

  1. The resource is not started. Open the console and run ensure my_inventory. If it fails to start, fix that first.
  2. It started after the caller. The export only exists once the owner has loaded its scripts. See start order in server.cfg and put the owner above the scripts that use it.
  3. The name is misspelled. Export names are case sensitive: getCount and GetCount are different.
  4. Wrong side. A server script cannot call a client export, and the other way round. The error looks the same.
  5. The export is declared but the function is missing. With the manifest style, server_exports { 'getCount' } needs a global function called getCount on the server. A local function does not count.
  6. The owner failed or was stopped. If it crashed on a script error, or you stopped it, its exports are gone until it runs again. Read its startup output in the console.

For the real-world versions of this error, see No such export GetSharedObject in resource es_extended and QBCore is nil: GetCoreObject.

Make the order certain with dependencies

Do not rely on the order of ensure lines alone. Declare the dependency in the manifest of the script that calls the export:

lua
dependency 'my_inventory'

FiveM then starts my_inventory first, and refuses to start your resource if it is missing, with a clearer message (could not find dependency).

Handling a missing resource gracefully

If another resource is optional, check its state before you call it:

lua
if GetResourceState('my_inventory') == 'started' then
    local count = exports.my_inventory:getCount(source, 'water')
end

GetResourceState returns a string such as started, stopped, starting or missing. It is the clean way to support an optional integration without a console error.

Calling your own exports

A resource can call its own exports too, with its own name: exports['my_inventory']:getCount(...). For a function that is only used inside the resource, a normal local function is faster and simpler. Exports are for the boundary between resources.

A word on performance

Every call crosses between two resources, so it is slower than a normal function call. Do not call an export in a tight per-frame loop if you can read the value once and keep it. Calling one a few times per second is fine.

Checklist

Symptom Fix
No such export x in resource y Start y, and put it before the caller in server.cfg
Works on the server, fails on the client Define the export in a client script too, or call it from the server
Manifest style export missing Define a global function with the same name as the manifest entry
Name case differs Match the spelling exactly
Resource name has a dash exports['my-resource']:name()
Optional integration spams the console Check GetResourceState('x') == 'started' first

Quick answers

How do I call an export from another resource?

Use exports['resource_name']:exportName(args) or exports.resource_name:exportName(args). The other resource must be started and must define that export on the same side (client or server).

Do I still need exports in fxmanifest.lua?

Not with exports('name', fn): it registers the export from the script itself. The exports {} and server_exports {} lists in the manifest are the older style, where a global function is exposed by name.

Why does an export work on the client but not on the server?

Client and server exports are separate. An export defined in a client script only exists on the client, and one defined in a server script only on the server.

Scripts that skip this problem

Item Creator V2Create usable items with animations, props, effects and more β€” without writing code.View script β†’Mic PhoneA foldable phone that unfolds into a tablet and carries onto a player's real phone.View script β†’Shop CreatorBuild a shop in under a minute β€” owners, employees, vaults and robberies included.View script β†’

Keep reading