d0p3t / fivem-js

Javascript and Typescript wrapper for the FiveM natives API
https://d0p3t.nl
Other
143 stars 57 forks source link

Example Resource - ReferenceError: PlayerId is not defined #28

Closed Lubjan closed 5 years ago

Lubjan commented 5 years ago

Hey, similar to Issue #6 I get an error when trying to execute the /adder example command, but it always throws the following error:

Error: (node:140084) UnhandledPromiseRejectionWarning: ReferenceError: PlayerId is not defined
    at Function.get Player [as Player] (dist/server.js:356:24)
    at Function.get PlayerPed [as PlayerPed] (dist/server.js:363:21)
    at dist/server.js:1399:72
    at Generator.next (<anonymous>)
    at dist/server.js:1394:71
    at new Promise (<anonymous>)
    at __awaiter (dist/server.js:1390:12)
    at Object.RegisterCommand [as callback] (dist/server.js:1398:44)
    at citizen:/scripting/v8/main.js:96:41
Error: (node:140084) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside 
of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Error: (node:140084) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I'm using the Typescript example resource, I have not tested it with the Javascript example, every dependencies and the server itself are a fresh install.

The command is the exact copy from here, the only changes I've made to the example resource are the package.json dependencies, the __resource.lua so that it takes a client and a server script and added a copy of the config.js for a client and server one, contents below.

__resource.lua

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

dependency 'webpack'

webpack_config 'client.config.js'
webpack_config 'server.config.js'

client_script 'dist/client.js'
server_script 'dist/server.js'

package.json

{
    "name": "fivem-js-example-typescript",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "author": "",
    "license": "ISC",
    "dependencies": {
        "fivem-js": "^1.1.1",
        "webpack": "^4.35.0",
        "@types/node":" ^12.0.10"
    },
    "devDependencies": {
        "ts-loader": "^5.3.3",
        "typescript": "^3.3.3333",
        "@citizenfx/client": "^1.0.1370-1"
    }
}

server.config.js:

const webpack = require('webpack');

module.exports = {
    entry: './src/server.ts',
    mode: 'production',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
        ],
    },
    optimization: {
        minimize: false,
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
    },
    output: {
        filename: 'server.js',
        path: __dirname + '/dist/',
    },
};

client.config.js

const webpack = require('webpack');

module.exports = {
    entry: './src/client.ts',
    mode: 'production',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
        ],
    },
    optimization: {
        minimize: false,
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
    },
    output: {
        filename: 'client.js',
        path: __dirname + '/dist/',
    },
};
d0p3t commented 5 years ago

I'll try to repro this by the end of the weekend

d0p3t commented 5 years ago

It looks like you are using an old version of fivem-js 1.1.1. Make sure you update to 1.3.0. There were some issues with the examples of that version. There were some issues with the examples in 1.3.0 too though. I will fix them in an upcoming commit (a couple of minutes from the time of writing).

As for building without the FiveM builders, I suggest you checkout fivem-ts-boilerplate.

Edit: See https://github.com/d0p3t/fivem-js/tree/master/examples/typescript for updated examples. Let me know if you're still having issues

Lubjan commented 5 years ago

Hey, thanks for helping, I've updated my test resource with the changes from the example, but sadly I still get the same error. I've made a repo with the resource as I use it: https://github.com/Lubjan/lun-admin I will have a look at the boilerplate in the meantime

Error: (node:6464) UnhandledPromiseRejectionWarning: ReferenceError: PlayerId is not defined
    at Function.get Player [as Player] (dist/server.js:356:24)
    at Function.get PlayerPed [as PlayerPed] (dist/server.js:363:21)
    at dist/server.js:1399:72
    at Generator.next (<anonymous>)
    at dist/server.js:1394:71
    at new Promise (<anonymous>)
    at __awaiter (dist/server.js:1390:12)
    at Object.RegisterCommand [as callback] (dist/server.js:1398:44)
    at citizen:/scripting/v8/main.js:96:41
Error: (node:6464) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Error: (node:6464) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) are not handled will terminate the Node.js process with a non-zero exit code. 

I've looked if fivem-js is up-to-date but it seems so

PS Q:\FX1\server-data\resources\[lun]\admin> npm list fivem-js
lun-admin@1.0.0 Q:\FX1\server-data\resources\[lun]\admin
`-- fivem-js@1.3.0
Lubjan commented 5 years ago

Okay, I've made the same mistake as #6 and have misread "server_script "dist/index.js" instead of client_script "dist/index.js"" as use server_script instead of client_script.

Thanks for the help and sorry for bothering your again.