multer-gridfs-storage icon indicating copy to clipboard operation
multer-gridfs-storage copied to clipboard

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

Open sanjarbek-ismatov opened this issue 1 year ago • 34 comments

image_1 image_2

sanjarbek-ismatov avatar Sep 08 '23 14:09 sanjarbek-ismatov

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"
  },

cleaverm avatar Sep 11 '23 09:09 cleaverm

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.

theBGuy avatar Oct 06 '23 22:10 theBGuy

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

sanjarbek-ismatov avatar Oct 07 '23 03:10 sanjarbek-ismatov

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 avatar Oct 11 '23 18:10 ghost

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.

ghost avatar Oct 11 '23 18:10 ghost

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

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

jasonhis avatar Oct 27 '23 10:10 jasonhis

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

anshvert avatar Nov 05 '23 10:11 anshvert

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

ARedmanDodd avatar Nov 06 '23 11:11 ARedmanDodd

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

AmanSingh44 avatar Nov 14 '23 11:11 AmanSingh44

Resolved by #561

meme8383 avatar Nov 21 '23 22:11 meme8383

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 avatar Nov 21 '23 23:11 meme8383

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.

meme8383 avatar Nov 22 '23 00:11 meme8383

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

Arko0809 avatar Jan 03 '24 06:01 Arko0809

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

Aakash-bhandari avatar Jan 10 '24 03:01 Aakash-bhandari

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)

amjad-awan avatar Jan 16 '24 18:01 amjad-awan

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?

arunwad avatar Jan 25 '24 13:01 arunwad

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.

meme8383 avatar Jan 26 '24 19:01 meme8383

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

arunwad avatar Jan 27 '24 17:01 arunwad

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?

ahsanch445 avatar Jan 31 '24 10:01 ahsanch445

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.

meme8383 avatar Jan 31 '24 19:01 meme8383

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

alanpurple avatar Mar 26 '24 17:03 alanpurple

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

kumar11473 avatar Mar 27 '24 16:03 kumar11473

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.

meme8383 avatar Mar 27 '24 21:03 meme8383

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

alanpurple avatar Mar 28 '24 07:03 alanpurple

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?

kumar11473 avatar Mar 28 '24 10:03 kumar11473

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?

https://github.com/devconcept/multer-gridfs-storage/compare/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.

meme8383 avatar Mar 28 '24 17:03 meme8383

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 ?

vanitharc12 avatar Apr 01 '24 02:04 vanitharc12

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

KoushikBaagh avatar May 02 '24 17:05 KoushikBaagh

By downgrading the mongoDB version issue is fixed

npm i [email protected]

This worked for me also

krishna102001 avatar Jun 16 '24 13:06 krishna102001

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.

krishna102001 avatar Jun 16 '24 14:06 krishna102001