sebelga / gstore-node

Google Datastore Entities Modeling for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gstore node 7.2.8 TypeError: OptionalDataloader is not a constructor

Startouf opened this issue · comments

Description

I recently updated may of my project files including firebase, my angular frontend, and ran npm audit fix --force on the backend side where I have an express JS app and gstore-node

Since then, I run into this error when starting my backend

TypeError: OptionalDataloader is not a constructor
    at Object.exports.createDataLoader (/app/node_modules/gstore-node/lib/dataloader.js:36:12)
    at Gstore.createDataLoader (/app/node_modules/gstore-node/lib/index.js:152:29)
    at Function.__populate (/app/node_modules/gstore-node/lib/model.js:471:70)
    at Function.get (/app/node_modules/gstore-node/lib/model.js:127:32)
    at Function.Model.findUserToAuthenticate (/app/src/models/user.model.js:112:33)
    at onFacebookAuthenticate (/app/src/appbase/auth.ts:56:36)

My findUserToAuthenticate method just calls existing_user = await Model.get(id); where Model = gstore.model(schemaName, userSchema);

Environment

  • OS - OS name and version : macbook m2 macOs 14.2 (23C64)
  • node - node version : v18.19.0
  • gstore-node - package version : "gstore-node": "^7.2.8",

Expected behavior

Describe what you expected to happen

Actual behavior

My backend crashes with the described error

Reproduction

Not really sure what may have caused this issue. I'm runing everything from docker-compose but it used to run fine. I will try to isolate package changes when I have time

Possible solution

N/A

Are you using yarn? Seems like the optional package is not able to resolve the dataloader import and it is configured to return null if the import couldn't be resolved. As a workaround, I have patched the package to removed the usage of optional package and require the package directly which works:

diff --git a/lib/dataloader.js b/lib/dataloader.js
index 53ea6d2d2dd..a50fa4df250 100644
--- a/lib/dataloader.js
+++ b/lib/dataloader.js
@@ -4,10 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
 };
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.createDataLoader = void 0;
-const optional_1 = __importDefault(require("optional"));
 const arrify_1 = __importDefault(require("arrify"));
 const nsql_cache_datastore_1 = __importDefault(require("nsql-cache-datastore"));
-const OptionalDataloader = (0, optional_1.default)('dataloader');
+const OptionalDataloader = require('dataloader');
 const dsAdapter = (0, nsql_cache_datastore_1.default)();
 const { keyToString } = dsAdapter;
 /**