NodeJS - Bluebird error

Hello,
As referenced in another thread there seems to be an issue with all NPM modules using “Bluebird”.
Tons of modules have Bluebird as dependency, and it seems the FiveM node version is incompatible with the way stack traces/error handlers are implemented using Bluebird.

@element.93 looked at this in the last thread - but I unfortunately can’t reply to it.

Do you know a workaround, or something I can do to get around this? Really need to use Mongoose for database handling, but it requires bluebird.

The outputted error after a simple “const mongoose = require(‘mongoose’);”

Error loading script dist/server.js in resource viverp: TypeError: firstLineError.stack.split is not a function
stack:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Failed to load script dist/server.js.
1 Like

I believe @sadboilogan had a quick fix for this.

Yeah he says you could remove the Bluebird package - but that doesn’t work unfortunately.

Hey ! I’m the guy from that old thread.
I spent a few hours trying to modify the mongoose package to make it work but to no avail.
I decided to work with the classic mongodb npm package.
It isn’t as complete but that’s the only workaround I have found.
If you find a way to make mongoose work, I’ll love to know it !
Good luck :smiley:

Hello!
Thanks for the follow up.
Yeah I’ve been trying to modify Mongoose aswell, but doesn’t seem to resolve it.

Gonna end up using the standard mongodb package, and writing some more advanced logic around that instead.

1 Like

Hi! I found the same problem so i modified the bluebird package to handle Fivem Nodejs core.
Add
“resolutions”: {
“bluebird”: “https://github.com/takiguru/bluebird
},
to your package.json. It will override all other package bluebird library with my one and you can use any package that using bluebird :slight_smile: . I’m using yarn and i don’t know it will work with npm too. I tried with mongoose and typeorm and it looks fine. If you find any bug or error pm me and i can check it out :slight_smile:

Hello @takiguru - thanks for the answer! :slight_smile:
I have also switched over to using yarn, and have tried using your bluebird package to resolve the issue - but it still persists.

I have confirmed it is using your code, and that your changes are in the package.

Either way, bluebird is an extremely common library (especially for some of the larger ORMs).
Is there any update as to whether or not this will be fixed in the FiveM node version? (@plutonium @nta) If anyone needs steps to reproduce here is an extremely simple rundown:

  1. Create a JS FXServer resource (for example using this boilerplate: https://github.com/d0p3t/fivem-ts-boilerplate)
  2. Install an ORM library (Mongoose, Mikro-ORM (currently using), Prisma, etc.)
  3. As soon as you start using any functions in these libraries, everything works perfectly - until we start the resource with FiveM, where we get this error:
Error loading script dist/server.js in resource RESOURCENAME: TypeError: (intermediate value).stack.split is not a function.
stack:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],
Failed to load script dist/server.js

There seems to be something wrong with how the FiveM node implementation handles this (sorry if I’m not correct, not an expert).

Thanks! :slight_smile:

1 Like

Hi @TheDumpap !
I’m using this approach for a while now in my resource. It looks like you didn’t added the “resolutions” parameter to the package.json. If you not add it properly yarn can’t override bluebird package. I’m using this method with mongoose without any problem. The source of the problem is in the Fivem custom console class. FIvem team said they are not using the common console class, i think mostly because it not compactible with their debug flow. Bluebird failing by default, because it contains an approach to print async stack traces to console, but Fivem console class is different than the normal and it fails. My fix was a simple hack to skip that check.

Wow, quick response I’ve gotta say! :slight_smile:

I have added the resolutions parameter with your resolution for bluebird from your repository.
This can also be seen if I look in the node_modules folder, your changes are in the bluebird source files correctly.

So I’m simply not sure why it’s not working correctly :confused:

i can confirm, using your custom bluebird libraries also solves rethinkdb usage.
thanks!

I have tried debugging the bluebird package a bit more, and I can see that firstLineError and lastLineError are both objects, so therefore it should be setting them to 0. Either way, even if I set them to always be 0 - it still throws the same error.

Hey! Sorry for writing so much - but I finally fixed the issue.
It did not even stem from the bluebird library, but the same kind of code was implemented into another one of my modules (mikro-orm).

The whole issue stems from the fact that the stack in FiveM’s Node version is an object containing these three properties: “file”, “line”, “name”.
In “regular” node, the stack is just expected to contain the “name” property directly (if I understand it correctly).

Either way, it could easily be modified by mapping the object to an array containing the “name” property.

File: ./node_modules/mikro-orm/dist/utils/Utils.js

Before:

stack = stack || new Error().stack.split('\n');

After:

stack = stack || [new Error().stack.map(a => a.name)];