bubbleChaser
bubbleChaser

Reputation: 925

Strapi + Heroku deployment failed:npm ERR! code ERESOLVE

I'm following this tutorial to deploy the Strapi app to Heroku.

I have set up to auto-deploy from my Github repo.

After pushing to Github, I get the notification of build failure with the following message.

build log

-----> Building on the Heroku-20 stack
-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       
-----> Installing binaries
       engines.node (package.json):  >=10.16.0 <=14.x.x
       engines.npm (package.json):   >=6.0.0
       
       Resolving node version >=10.16.0 <=14.x.x...
       Downloading and installing node 14.15.4...
       Bootstrapping npm >=6.0.0 (replacing 6.14.10)...
       npm >=6.0.0 installed
       
-----> Installing dependencies
       Installing node modules (package.json)
       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/knex
       npm ERR!   knex@"<0.20.0" from the root project
       npm ERR! 
       npm ERR! Could not resolve dependency:
       npm ERR! peer knex@"^0.20.0" from [email protected]
       npm ERR! node_modules/strapi-connector-bookshelf
       npm ERR!   strapi-connector-bookshelf@"3.4.6" 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.
       npm ERR! 
       npm ERR! See /tmp/npmcache.9OnCF/eresolve-report.txt for a full report.
       
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.9OnCF/_logs/2021-02-04T02_14_54_807Z-debug.log
-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       Some possible problems:
       
       - Dangerous semver range (>) in engines.node
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

What should I do here? Any help would be appreciated.

Upvotes: 2

Views: 2462

Answers (3)

Ehsan Paknejad
Ehsan Paknejad

Reputation: 688

Jryke's way solved my problem:

I added these lines to package.json and the problem fixed:

  "engines": {
    "node": "16.x",
    "npm": "8.5.5"
  },

And again thanks to Jryke :-) yes I use "knex" module in my code and yes I use "heroku" also.

Upvotes: 2

Hard Monkey PC
Hard Monkey PC

Reputation: 63

In my case .npmrc solved this,

create .npmrc in the root of the project and allow legacy peer dependencies

legacy-peer-deps=true

Upvotes: 4

Jryke
Jryke

Reputation: 148

I had the same issue today. It appears to me that the problem has to do with the version of knex not being compatible with the version of nodejs. After looking into it more, Strapi isn't compatible with nodejs over v.14 or npm over v.6 (Heroku was trying to build my Strapi app with node v.15). To resolve it, I updated the package.json file to make sure that Heroku uses the versions that are compatible. Here is what I added, it worked for me and I hope it works for you.

In the package.json file, update the versions of node and npm like this:

"engines": {
  "node": "<=14.x.x",
  "npm": "<=6.x.x"
}

Upvotes: 8

Related Questions