notum-cz / strapi-plugin-record-locking

This plugin provides the functionality to prevent data loss in cases where multiple users are simultaneously editing the same record within STRAPI v4.
20 stars 7 forks source link

Bug: TypeError: Cannot read properties of undefined (reading 'query') #69

Closed mstroiu closed 3 months ago

mstroiu commented 7 months ago

Hi there,

I've stumbled across this type of error while generating the types using npm run strapi ts:generate-types --verbose and I'm not sure if I'm doing something wrong or if is a real bug.

Output:

npm run strapi ts:generate-types --verbose
npm verb cli /.nvm/versions/node/v20.10.0/bin/node /Users/*****/.nvm/versions/node/v20.10.0/bin/npm
npm info using npm@10.2.3
npm info using node@v20.10.0
npm verb title npm run strapi ts:generate-types
npm verb argv "run" "strapi" "ts:generate-types" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:/.npm/_logs/2024-02-07T19_34_38_766Z-
npm verb logfile /.npm/_logs/2024-02-07T19_34_38_766Z-debug-0.log

> dxw-cms@0.12.0 strapi
> strapi ts:generate-types

Starting the compilation for TypeScript files in ***********/************/*********/***
[INFO]  [2024-02-07T19:34:42.749Z] (Typegen) Starting the type generation process
[INFO]  [2024-02-07T19:34:42.749Z] (Typegen) Generating types for contentTypes
(node:76434) Warning: The upload provider "strapi-provider-upload-static-service" doesn't implement the uploadStream function. Strapi will fallback on the upload method. Some performance issues may occur.
(Use `node --trace-warnings ...` to show where the warning was created)
[INFO]  [2024-02-07T19:34:42.971Z] (Typegen) Generating types for components
[INFO]  [2024-02-07T19:34:43.077Z] (Typegen) Saved contentTypes types in ../../../../../types/generated/contentTypes.d.ts
[INFO]  [2024-02-07T19:34:43.077Z] (Typegen) Saved components types in ../../../../../types/generated/components.d.ts
[INFO]  [2024-02-07T19:34:43.077Z] (Typegen) The task completed successfully with 0 warning(s) and 0 error(s) in 0.328s.
/node_modules/@notum-cz/strapi-plugin-record-locking/server/destroy.js:7
  strapi.db.query("plugin::record-locking.open-entity").deleteMany();
            ^

TypeError: Cannot read properties of undefined (reading 'query')
    at module.exports [as destroy] (node_modules/@notum-cz/strapi-plugin-record-locking/server/destroy.js:7:13)
    at Object.destroy (/node_modules/@strapi/strapi/lib/core/domain/module/index.js:54:45)
    at Object.destroy (/node_modules/@strapi/strapi/lib/core/registries/modules.js:38:19)
    at async Strapi.runLifecyclesFunctions (/node_modules/@strapi/strapi/lib/Strapi.js:546:5)
    at async Strapi.destroy (/node_modules/@strapi/strapi/lib/Strapi.js:231:5)

Node.js v20.10.0
npm verb exit 1
npm verb code 1

I'm using the following dependencies

Let me know if you need more information

Thank you

broksonic21 commented 5 months ago

Similar to my issue here: https://github.com/notum-cz/strapi-plugin-record-locking/issues/83, seems like a general CLI use case issue?

omikulcik commented 3 months ago

Thank you for reporting this. I have fixed this by adding optional chaining in https://github.com/notum-cz/strapi-plugin-record-locking/commit/afd8b915d10b7da9b93290c59bf4cfd9c1d71b04 and will release new version.