project-error / npwd

NPWD is a FiveM phone resource written entirely in TypeScript and React.
https://projecterror.dev
Other
351 stars 275 forks source link

Support: use server export (JS) in custom app #1143

Open postb99 opened 6 months ago

postb99 commented 6 months ago

Development Issue

Unsure

Phone Version

master

Issue Description

I started rewriting an npwd's working app server.lua to server.ts. I don't know what I miss to be able to use onMessage export (see https://projecterror.dev/docs/npwd/api/server-exports/ the Lua and JS code are almost the same).

I also read the FAQ (https://projecterror.dev/docs/npwd/faq/#errors) and have useResourceIntegration set to true.

As on the server-exports page I don't have much code, but when I hit F12 on "exports" (in VS Code) it browses to @citizenfx/server so what do I miss to install or configure?

import { oxmysql as MySQL } from '@overextended/oxmysql';
import { OnMessageExportCtx } from '@npwd/types';
const ESX  = exports['es_extended'].getSharedObject();

console.log('Server started.');

exports.npwd.onMessage(value.num, (ctx: OnMessageExportCtx) => {
        console.log(ctx);
}));

Thanks a lot.

Issue Reproduction

  1. Setup sample app from template
  2. Install "@npwd/types" package (npm install --save-dev)
  3. update server.ts code as described
  4. compile my app
  5. run FxServer that loads the app and logs Error: No such export onMessage in resource npwd

Evidence

No response