简体   繁体   中英

Deploying Node.JS app to Heroku - Caching issues?

I'm currently trying to push my app to Heroku. I already been able to deploy it a few times, but now I've updated mongoose from ">= 3.5.0" to ">= 3.6.0rc0" in my packages.json file. However, version 3.6 requires mpath and mpromise.

When the slug compilation begins, it uses a cached version of mongoose or something, as my when my application launches, I get "Error: Cannot find module 'mpath'".

I trying to setup a custom buildpack Git that would stop the caching, I just commented out the cache stuff in bin/compile, available here: https://github.com/jValdron/heroku-buildpack-nodejs

Here is an output of the push: http://pastebin.com/L3Yqy2NR

Also, when I removed some dependencies from package.json, if I login with 'heroku run bash', I can see that those removed dependencies in node_modules. I already tried to remove the node_modules folder and do another 'git push', that didn't work either. And those removed deps are still in node_modules.

Anyone have an idea on how to fix this?

EDIT:

Here is my package.json file:

{
    "name": "souply-api",
    "version": "0.1.0",
    "author": "Jason Valdron <jason.valdron@orangesprocket.com>",
    "description": "Main gears that runs the Soup.ly application",
    "dependencies": {
        "bcrypt": ">= 0.7.3",
        "express": ">= 3.0.5",
        "extend": ">= 1.1.3",
        "imagemagick": ">= 0.1.3",
        "jade": ">= 0.27.7",
        "knox": ">= 0.4.6", 
        "less": ">= 1.3.1",
        "less-middleware": ">= 0.1.9",
        "moment": ">= 1.7.2",
        "mongoose": ">= 3.6.0rc0", 
        "mongoose-types": ">= 1.0.3",
        "node-native-zip": ">= 1.1.0",
        "nodemailer": ">= 0.3.37",
        "oauth2orize": ">= 0.1.0",
        "passport": ">= 0.1.15",
        "passport-local": ">= 0.1.6",
        "passport-google": ">= 0.2.0",
        "passport-facebook": ">= 0.1.4",
        "passport-twitter": ">= 0.1.4",
        "passport-http": ">= 0.2.1",
        "passport-http-bearer": ">= 0.2.0",
        "passport-oauth2-client-password": ">= 0.1.0",
        "poor-form": ">= 1.1.3",
        "request": ">= 2.12.0",
        "socket.io": ">= 0.9.13"
    },
    "engines": {
        "node": "0.8.x",
        "npm": "1.1.x"
    }
}

Mongoose is set as 3.6.0rc, as previously said. Mpath is a dependencies in Mongoose's package.json file. If I look at my local mongoose package.json file, I can see this:

"dependencies": {
    "hooks": "0.2.1"
  , "mongodb": "1.2.11"
  , "ms": "0.1.0"
  , "sliced": "0.0.3"
  , "muri": "0.3.0"
  , "mpromise": "0.2.0"
  , "mpath": "0.1.1"
}

Also, if I login with heroku run bash , and navigate to node_modules/mongoose/node_modules I see that mpath and mpromise is not there.

node_modules was in the Git repo. By removing it from the repo, it worked fine.

Now heroku supports disabling cache for node_modules: https://devcenter.heroku.com/articles/nodejs-support#cache-behavior

Heroku maintains a cache directory that is persisted between builds. This cache is used to store caches for npm, yarn, and bower. You can disable all caching for Node.js apps if you prefer:

heroku config:set NODE_MODULES_CACHE=false git commit -am 'disable node_modules cache' --allow-empty git push heroku master

you will need to update your package.json to be the latest version of mongoose you are using

you will need to add mpath to your package.json also (before the mongoose entry)

can you post your package.json file?

Remove cache of node_modules and redeploy it:

git rm -r --cached node_modules

and then git push heroku master

You can also disable the cache if you don't want cache node_module while re-deploying:

heroku config:set NODEMODULESCACHE=false
git commit -am 'rebuild' --allow-empty
git push heroku master
heroku config:unset NODEMODULESCACHE

Changing Node version in package.json did it for me.

For example:

"engines": {
    "node": "9.2.1"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM