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

error TypeError: Cannot read property '_id' of undefined #6640

Closed
PhantomxJoker opened this issue Jun 12, 2020 · 18 comments
Closed

error TypeError: Cannot read property '_id' of undefined #6640

PhantomxJoker opened this issue Jun 12, 2020 · 18 comments

Comments

@PhantomxJoker
Copy link

PhantomxJoker commented Jun 12, 2020

When I migrate from alpha to v3.0.0, had an error about user-permissions plugin:
error Bootstrap function in plugin "users-permissions" failed [2020-06-12T01:15:06.300Z] error TypeError: Cannot read property '_id' of undefined at dbPermissions.map.p (/usr/src/app/node_modules/strapi-plugin-users-permissions/services/UsersPermissions.js:267:59) at Array.map (<anonymous>) at Object.updatePermissions (/usr/src/app/node_modules/strapi-plugin-users-permissions/services/UsersPermissions.js:266:46) at processTicksAndRejections (internal/process/task_queues.js:86:5)

For reproduce the error, do the next:

  1. Migrate from alpha to RC3 using MongoDB
  2. Set port to 3000 and run serve

I guess that is something related to some DB collection but I'm no really sure

  • Node.js version: 12.16.1
  • NPM version: 6.13.4
  • Strapi version: v3.0.0
  • Database: MongoDB
  • Operating system: Ubuntu
@derrickmehaffy
Copy link
Member

Not sure where you got Strapi v1.0.0 but that version hasn't been supported in over 3 years and was built before the Alpha.

@PhantomxJoker
Copy link
Author

@derrickmehaffy Sorry for that, the version is the last RC, the v3.0.0

@derrickmehaffy
Copy link
Member

That honestly looks like you have some miss-matched versions or something odd going on with your db

@PhantomxJoker
Copy link
Author

Just a question, I jumped from beta 26 to RC 3.0.0. In that case, I have just to use strapi@beta for the installation? I was searching for a newest one but I did not find anything

@PhantomxJoker
Copy link
Author

I found the, I was running my Docker with an old version of Node.

Thank you

@hendrikgaffo
Copy link

I am getting the same error, but I did not upgrade anything. I am still running on v3.0.0-beta.20 since it was released. Interestingly everything works in dev (Ubuntu 16 LTS, Node 12.18.1), but not in production (Docker container with node:12.8.0-alpine).

@PhantomxJoker Which version of Node did you use in your container to make it work?

@PhantomxJoker
Copy link
Author

Hi @hendrikgaffo ! I'm using the same version as you, but with the change I made a clean build too (using npm run build --clean). Not sure if did the trick, but worked for me

@weilaiqishi
Copy link

the same error, on strapi the same 3.0.5, in my mongodb user-permission-permission table, some data without role, so dbPermissions.map err

@basavarajdodamani
Copy link

the same error, on strapi the same 3.0.5, in my mongodb user-permission-permission table, some data without role, so dbPermissions.map err

Thanks for the hint @weilaiqishi ... We resolved this by removing the document from MONGODB without role! But this should not happen again, observation was that when a route and controller gets edited inthe project directory, it throws this issue. Route and controller files should be replaced as a whole when promoting code from one env to another.
I am not sure if there are any other rootacuses for this issue.

@Blessen
Copy link

Blessen commented Dec 28, 2020

Thankyou!!

@MightyMoud
Copy link

MightyMoud commented Jan 2, 2021

Just ran into this out of nowhere... didn't even need to reset my db to get across it.
Strapi 3.3.4

@shivagouraram
Copy link

shivagouraram commented Mar 21, 2021

I encountered this issue today on version 3.5.3 when I was editing routes and controllers on my local instance. Deleting the records in user-permission-permission with empty role has resolved the issue. Thanks @basavarajdodamani

@bbrez1
Copy link

bbrez1 commented Mar 26, 2021

We have encountered this issue many times on our live server. It just happens out of nothing. It's very time-consuming to delete and re-do everything (a lot of tables to re-do all the permissions) + it shouldn't really crash the live server. Does anyone have any solution? This has happened on multiple versions already. Currently we're running 3.5.3

@bbrez1
Copy link

bbrez1 commented Apr 20, 2021

Still no solution? This makes Strapi completely unusable in production.

@priyadarsh
Copy link

I encountered this issue today on version 3.5.3 when I was editing routes and controllers on my local instance. Deleting the records in user-permission-permission with empty role has resolved the issue. Thanks @basavarajdodamani

deleting the records with the below criteria on users-permissions_permission collection did solve the problem. But don't know the root cause

{"role": { $exists: false} }

@derrickmehaffy
Copy link
Member

This issue has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/bug-in-production/9122/3

@phamminhkhoa
Copy link

i go to DB and filter {"role": { $exists: false} } and fixed it but i don't know why it work

@irenefelita192
Copy link

thank you this post saved me, I got same problem on version 3.6.8, don't know why suddenly some roles are missing when I only upload some images. Got it working when I update the role at users-permissions_permission table (not delete it)

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