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

uncaughtException: Cannot read properties of undefin ed (reading '_id') #560

Open
sanjarbek-ismatov opened this issue Sep 8, 2023 · 34 comments
Labels
bug A feature or code that is not working properly

Comments

@sanjarbek-ismatov
Copy link

image_1
image_2

@sanjarbek-ismatov sanjarbek-ismatov added the bug A feature or code that is not working properly label Sep 8, 2023
@cleaverm
Copy link

I started getting this error last week after updating a couple of MongoDB-related dependencies in a project. mongodb is at 4.17.1 in the project but Yarn was installing some 6.x.x versions for other dependencies.

Putting this in package.json has resolved it for me:

  "resolutions": {
    "mongodb": "4.17.1"
  },

@theBGuy
Copy link

theBGuy commented Oct 6, 2023

Also getting this error, changing the mongodb version didn't fix it for me. I have tracked down the error (at least mine) to fromMulterStream method. The value passed to emitFile when the finish event is triggered is undefined.

@sanjarbek-ismatov
Copy link
Author

Also getting this error, changing the mongodb version didn't fix it for me. I have tracked down the error (at least mine) to fromMulterStream method. The value passed to emitFile when the finish event is triggered is undefined.

It helped me, it's working correctly

@theBGuy theBGuy mentioned this issue Oct 7, 2023
1 task
@ghost
Copy link

ghost commented Oct 11, 2023

Hi, this error still is problem for someone. May you help me ?

[1] TypeError: Cannot read properties of undefined (reading '_id')
[1] at GridFSBucketWriteStream.emitFile (/home/cppdozer/Projects/encore/server/node_modules/multer-gridfs-storage/src/gridfs.ts:353:12)
[1] at GridFSBucketWriteStream.emit (node:events:529:35)
[1] at GridFSBucketWriteStream.emit (node:domain:489:12)
[1] at finish (node:internal/streams/writable:748:10)
[1] at processTicksAndRejections (node:internal/process/task_queues:82:21)
[1] [nodemon] app crashed - waiting for file changes before starting...

@ghost
Copy link

ghost commented Oct 11, 2023

Hi, this error still is problem for someone. May you help me ?

[1] TypeError: Cannot read properties of undefined (reading '_id') [1] at GridFSBucketWriteStream.emitFile (/home/cppdozer/Projects/encore/server/node_modules/multer-gridfs-storage/src/gridfs.ts:353:12) [1] at GridFSBucketWriteStream.emit (node:events:529:35) [1] at GridFSBucketWriteStream.emit (node:domain:489:12) [1] at finish (node:internal/streams/writable:748:10) [1] at processTicksAndRejections (node:internal/process/task_queues:82:21) [1] [nodemon] app crashed - waiting for file changes before starting...

I just installed mongodb module in my project and problem solved immediately.

@jasonhis
Copy link

If you are using yarn, adding this to the package.json will fix it.

  "resolutions": {
    "multer-gridfs-storage/mongodb": "^5.9.1"
  },

@anshvert
Copy link

anshvert commented Nov 5, 2023

If you are using yarn, adding this to the package.json will fix it.

  "resolutions": {
    "multer-gridfs-storage/mongodb": "^5.9.1"
  },

This Worked for me. TY

@ARedmanDodd
Copy link

I just had this same issue, however Im not using Yarn.
To resolve I needed to install mongodb v5.9.1

npm install [email protected]

This instantly fixed the issue

@AmanSingh44
Copy link

I just had this same issue, however Im not using Yarn. To resolve I needed to install mongodb v5.9.1

npm install [email protected]

This instantly fixed the issue

This worked for me, before trying this i didn't had the mongodb module in my project, latest version also works. Thank you, can finally upload images

@meme8383
Copy link

Resolved by #561

@meme8383
Copy link

I made a fork if you would like to use the latest versions of mongoose/mongodb, add "multer-gridfs-storage": "meme8383/multer-gridfs-storage#f82252c" to your package.json (add commit or maintain your own fork for security). Tested on mongodb 6.3.0 and mongoose 8.0.1.

@meme8383
Copy link

Fixed another issue relating to file count limits and mongodb update in commit 32d2198. Feel free to use my fork or make your own as it appears this package is no longer maintained.

@Arko0809
Copy link

Arko0809 commented Jan 3, 2024

If you dont have mongodb installed in your project and multer and multer-gridfs-storage installed; you will get error while installing mongodb by multer and multer-gridfs-storage.
Step 1 :
npm uninstall multer multer-gridfs-storage

Step 2 :
npm i [email protected] (In my case only this version worked. Check with the latest version first otherwise this is your only option)

Step 3:
npm i multer-gridfs-storage

Step 4:
npm i multer

@Aakash-bhandari
Copy link

I just had this same issue, however Im not using Yarn. To resolve I needed to install mongodb v5.9.1
npm install [email protected]
This instantly fixed the issue

This worked for me, before trying this i didn't had the mongodb module in my project, latest version also works. Thank you, can finally upload images

Can you share you Package.json file

@amjad-awan
Copy link

i have this same error, my dependencies are "mongoose": "^8.0.4",
"multer": "^1.4.4",
"multer-gridfs-storage": "^5.0.2",
D:\All\MearStackProject\music-app\backend\node_modules\multer-gridfs-storage\lib\gridfs.js:306
id: f._id,
^

TypeError: Cannot read properties of undefined (reading '_id')
at GridFSBucketWriteStream.emitFile (D:\All\MearStackProject\music-app\backend\node_modules\multer-gridfs-storage\lib\gridfs.js:306:31)

@arunwad
Copy link

arunwad commented Jan 25, 2024

I have the same issue and want to try the fix in meme8383's fork. I am a newbie and am reading up on how to do so. How does a bug fix get incorporated in the latest version that is downloadable using npm?

@meme8383
Copy link

I have the same issue and want to try the fix in meme8383's fork. I am a newbie and am reading up on how to do so. How does a bug fix get incorporated in the latest version that is downloadable using npm?

The author has to merge a fix and publish it. I was going to rewrite this library, but I switched to using an actual cloud provider for cloud storage instead. You can use my fork by setting the version to meme8383/multer-gridfs-storage#32d2198 in your package.json.

@arunwad
Copy link

arunwad commented Jan 27, 2024

Thanks Meme8383, I cloned your fork and used it in my app and it works, .... problem solved.

@ahsanch445
Copy link

I have the same issue and want to try the fix in meme8383's fork. I am a newbie and am reading up on how to do so. How does a bug fix get incorporated in the latest version that is downloadable using npm?

The author has to merge a fix and publish it. I was going to rewrite this library, but I switched to using an actual cloud provider for cloud storage instead. You can use my fork by setting the version to meme8383/multer-gridfs-storage#32d2198 in your package.json.

can it work on production level?

@meme8383
Copy link

I have the same issue and want to try the fix in meme8383's fork. I am a newbie and am reading up on how to do so. How does a bug fix get incorporated in the latest version that is downloadable using npm?

The author has to merge a fix and publish it. I was going to rewrite this library, but I switched to using an actual cloud provider for cloud storage instead. You can use my fork by setting the version to meme8383/multer-gridfs-storage#32d2198 in your package.json.

can it work on production level?

That is for you to decide. This library has not been tested thoroughly with the most recent versions of these libraries. If it is necessary, I would recommend maintaining your own fork in case other issues need fixing. Using my fork with the commit reference should work fine as long as you thoroughly test your application.

However, I don't think you should be using MongoDB for file storage in production anyways.

@alanpurple
Copy link

is this repository dead? why no update over 3 years?

@kumar11473
Copy link

kumar11473 commented Mar 27, 2024

is this repository dead? why no update over 3 years?

Can't say yes or no but this issue isn't resolved yet. I'm still getting this error with latest version of Mongodb.
[email protected] works fine .

Screenshot 2024-03-27 212400

@meme8383
Copy link

is this repository dead? why no update over 3 years?

Can't say yes or no but this issue isn't resolved yet. I'm still getting this error with latest version of Mongodb. [email protected] works fine .

Screenshot 2024-03-27 212400

You can use my branch by adding meme8383/multer-gridfs-storage to your package.json, I fixed that and another issue. However, not a great fix, since optimally this should be rewritten and thoroughly tested for the newest versions.

@alanpurple
Copy link

alanpurple commented Mar 28, 2024

I admire @meme8383 's output, but this, https://github.com/lykmapipo/mongoose-gridfs, and https://github.com/aheckmann/gridfs-stream all should be properly updated to the latest mongodb driver for proper long-term projects

@kumar11473
Copy link

is this repository dead? why no update over 3 years?

Can't say yes or no but this issue isn't resolved yet. I'm still getting this error with latest version of Mongodb. [email protected] works fine .
Screenshot 2024-03-27 212400

You can use my branch by adding meme8383/multer-gridfs-storage to your package.json, I fixed that and another issue. However, not a great fix, since optimally this should be rewritten and thoroughly tested for the newest versions.

Its working. Thanks @meme8383. Can you please brief how you fixed it and came to know what function or file need to be fixed?

@meme8383
Copy link

is this repository dead? why no update over 3 years?

Can't say yes or no but this issue isn't resolved yet. I'm still getting this error with latest version of Mongodb. [email protected] works fine .
Screenshot 2024-03-27 212400

You can use my branch by adding meme8383/multer-gridfs-storage to your package.json, I fixed that and another issue. However, not a great fix, since optimally this should be rewritten and thoroughly tested for the newest versions.

Its working. Thanks @meme8383. Can you please brief how you fixed it and came to know what function or file need to be fixed?

master...meme8383:multer-gridfs-storage:master
Pretty simple fixes, but there are bound to be more issues. I was going to rewrite the library for the updated packages but we decided to switch away from using Mongo for file storage. Test your project thoroughly if you use this.

@vanitharc12
Copy link

Hi , Its throwing the above error in latest version or downgraded versions as well ."mongoose": "^8.2.4",
"multer": "^1.4.5-lts.1",
"multer-gridfs-storage": "^5.0.2", Does anyone resolved the issue with compatible versions? Can you tell me the versions used ?

@KoushikBaagh
Copy link

I just had this same issue, however Im not using Yarn. To resolve I needed to install mongodb v5.9.1

npm install [email protected]

This instantly fixed the issue

Working on date: 02/05/2024.
This issue still persists. only way is to downgrade to mongodb, 5.9.1

@krishna102001
Copy link

By downgrading the mongoDB version issue is fixed

npm i [email protected]

This worked for me also

@krishna102001
Copy link

Hi , Its throwing the above error in latest version or downgraded versions as well ."mongoose": "^8.2.4", "multer": "^1.4.5-lts.1", "multer-gridfs-storage": "^5.0.2", Does anyone resolved the issue with compatible versions? Can you tell me the versions used ?

just downgrade the multer version

npm install [email protected] --save

because there is dependency conflict between multer and multer-gridfs-storage. Specifically, [email protected] requires multer@^1.4.2.

@prince-sunsara
Copy link

Thank you so much, it's working

@Lilianada
Copy link

I use yarn
I downgraded the version of mongodb and added resolutions but none of it works
"mongodb": "5.9.1",
"mongoose": "^5.13.14",
"resolutions": {
"multer-gridfs-storage/mongodb": "^5.9.1"
}

Uncaught Exception: Cannot read properties of undefined (reading '_id')
TypeError: Cannot read properties of undefined (reading '_id')
at GridFSBucketWriteStream.emitFile

@prince-sunsara
Copy link

downgrade multer version

npm install [email protected] --save

@cpalmer-ios
Copy link

cpalmer-ios commented Sep 3, 2024

I found the error was occurring because the _id was coming back as undefined. I made a PR to use the id coming back from Mongo DB in the fromMulterStream function: #586

Had some trouble compiling the code (ts errors) so edited the system generated file directly so you'd see what I mean

the ts errors were coming from the following modules and file:

Found 7 errors in 5 files.

Errors  Files
     1  node_modules/@types/eslint/helpers.d.ts:1
     1  node_modules/@types/markdown-it/lib/index.d.ts:151
     1  node_modules/@types/mongodb/index.d.ts:58
     3  src/gridfs.ts:216
     1  ../../../../node_modules/@types/eslint/helpers.d.ts:1

Thanks, hope it helps !

axelav added a commit to axelav/multer-gridfs-storage that referenced this issue Dec 9, 2024
axelav added a commit to Axion-Ray/multer-gridfs-storage that referenced this issue Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A feature or code that is not working properly
Projects
None yet
Development

No branches or pull requests