node.jsherokudependenciesmultermulter-gridfs-storage

Dependency problem using multer and multer-gridfs-storage


First of all here I want to push my all files to heroku for hosting purpose and here I am not able to install dependency of multer and multer-gridfs-storage on heroku so that's why I am not able to host my website on heroku

remote: -----> Installing dependencies
remote:        Installing node modules
remote:        npm ERR! code ERESOLVE
remote:        npm ERR! ERESOLVE could not resolve
remote:        npm ERR!
remote:        npm ERR! While resolving: multer-gridfs-storage@5.0.2
remote:        npm ERR! Found: multer@1.4.5-lts.1
remote:        npm ERR! node_modules/multer
remote:        npm ERR!   multer@"^1.4.5-lts.1" from the root project
remote:        npm ERR!
remote:        npm ERR! Could not resolve dependency:
remote:        npm ERR! peer multer@"^1.4.2" from multer-gridfs-storage@5.0.2
remote:        npm ERR! node_modules/multer-gridfs-storage
remote:        npm ERR!   multer-gridfs-storage@"^5.0.2" from the root project
remote:        npm ERR!
remote:        npm ERR! Conflicting peer dependency: multer@1.4.4
remote:        npm ERR! node_modules/multer
remote:        npm ERR!   peer multer@"^1.4.2" from multer-gridfs-storage@5.0.2
remote:        npm ERR!   node_modules/multer-gridfs-storage
remote:        npm ERR!     multer-gridfs-storage@"^5.0.2" from the root project
remote:        npm ERR!
remote:        npm ERR! Fix the upstream dependency conflict, or retry
remote:        npm ERR! this command with --force, or --legacy-peer-deps
remote:        npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
remote:        npm ERR!
remote:        npm ERR! See /tmp/npmcache.fbHb6/eresolve-report.txt for a full report.
remote:
remote:        npm ERR! A complete log of this run can be found in:
remote:        npm ERR!     /tmp/npmcache.fbHb6/_logs/2022-10-22T21_00_27_665Z-debug-0.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed

Solution

  • The -lts.1 suffix on multer@"^1.4.5-lts.1" causes it not to be matched by the peer version constraint ^1.4.2 coming from multer-gridfs-storage@5.0.2. According to the npm semver calculator, the latest version of Multer that satisfies this version constraint is 1.4.4.

    Given that version 1.4.5-lts.1 appears to be a compatible continuation of the 1.x development line, and that Multer exists in the NPM ecosystem, I would argue that this is a bug in the Multer project¹. Its version numbers should satisfy NPM's understanding of semver.

    Your easiest solution will be to reduce your direct dependency on Multer from version ^1.4.5-lts.1 to version 1.4.4, which satisfies the peer dependency from Multer GridFS Storage. Hopefully you don't depend on any features or bug fixes in the newer version.

    I have submitted a bug against the Multer project suggesting that its LTS version constraints remain compatible with semver, assuming the 1.4.5-lts.1 version is actually supposed to be compatible with version 1.4.4 and earlier.


    ¹I am not knowledgeable enough in semver or NPM to know whether this implementation is actually correct. What matters is that the Multer project and NPM's implementation of semver appear to be in conflict.

    I believe the -lts.1 suffix is recognized as a prerelease (i.e., 1.4.4-lts.1 would come before 1.4.4). The semver calculator seems to agree: using a version constraint of >=1.4.2 <=1.4.4-lts.1 matches versions 1.4.2, 1.4.3, and 1.4.4-lts.1, but not 1.4.4.