Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gstore node 7.2.8 TypeError: OptionalDataloader is not a constructor #282

Open
Startouf opened this issue Dec 25, 2023 · 1 comment
Open

Comments

@Startouf
Copy link

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

@usmanmani1122
Copy link

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;
 /**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants