Home > Software design >  Unable to install node_modules in Express js
Unable to install node_modules in Express js

Time:09-26

I'm try to install node_modules from package.json file but i got error.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/mongoose
npm ERR!   mongoose@"^5.13.7" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer mongoose@"^4.1.12" from [email protected]
npm ERR! node_modules/mongoose-auto-increment
npm ERR!   mongoose-auto-increment@"^5.0.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

My package json dependencies

    "dependencies": {
    "express": "^4.17.1",
    "express-fileupload": "^1.2.1",
    "express-validator": "^6.12.1",
    "mongoose": "^5.13.7",
    "mongoose-auto-increment": "^5.0.1",
    "mongoose-sequence": "^5.3.1",
    "xml-formatter": "^2.6.1",
    "xml2json": "^0.12.0"
  }

how can i solve this.

EDIT:

I just run npm install i got below errors.

npm ERR! code 1
npm ERR! path <PROJECT-PATH>backend/node_modules/node-expat
npm ERR! command failed
npm ERR! command sh /tmp/install-1e860795.sh
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.8.10 found at "/usr/bin/python3"
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '<PROJECT-PATH>backend/node_modules/node-expat/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '<HOME-PATH>.cache/node-gyp/16.17.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=<HOME-PATH>.cache/node-gyp/16.17.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/usr/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=<HOME-PATH>.cache/node-gyp/16.17.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=<PROJECT-PATH>backend/node_modules/node-expat',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: not found: make
npm ERR! gyp ERR! stack     at getNotFoundError (/usr/lib/node_modules/npm/node_modules/which/which.js:10:17)
npm ERR! gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:57:18
npm ERR! gyp ERR! stack     at new Promise (<anonymous>)
npm ERR! gyp ERR! stack     at step (/usr/lib/node_modules/npm/node_modules/which/which.js:54:21)
npm ERR! gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:71:22
npm ERR! gyp ERR! stack     at new Promise (<anonymous>)
npm ERR! gyp ERR! stack     at subStep (/usr/lib/node_modules/npm/node_modules/which/which.js:69:33)
npm ERR! gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/which/which.js:80:22
npm ERR! gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/isexe/index.js:42:5
npm ERR! gyp ERR! stack     at /usr/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
npm ERR! gyp ERR! System Linux 5.15.0-46-generic
npm ERR! gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd <PROJECT-PATH>backend/node_modules/node-expat
npm ERR! gyp ERR! node -v v16.17.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok

CodePudding user response:

Did you read the error? That mongoose-auto-increment library requires version 4 of mongoose, but you have mongoose 5.

You can see if things might work by adding one of the options suggested in the error, i.e. npm i --legacy-peer-deps or npm i --force, or you might want to look for a newer versionf of mongoose-auto-increment that claims support for Mongoose 5 (though that seems to be unlikely, since that last version of that library was released 7 years ago).

CodePudding user response:

Would you please remove node_modules folder from the root of your project?

Then try to run

npm install

If this is still the problem. Try removing node_modules folder again and run

npm i --legacy-peer-deps

If this still not works, try to downgrade/upgrade the package mongoose-auto-increment

I hope those steps will work. Let me know this problem still persits.

  • Related