简体   繁体   English

将Node.JS应用程序部署到Heroku-缓存问题?

[英]Deploying Node.JS app to Heroku - Caching issues?

I'm currently trying to push my app to Heroku. 我目前正在尝试将我的应用程序推送到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. 我已经能够部署它几次,但是现在我在packages.json文件中将猫鼬从“> = 3.5.0”更新为“> = 3.6.0rc0”。 However, version 3.6 requires mpath and mpromise. 但是,版本3.6需要mpath和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'". 当slug编译开始时,它使用猫鼬之类的缓存版本,当我启动应用程序时,出现“错误:找不到模块'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 我试图设置一个自定义的buildpack Git来停止缓存,我只是在bin / compile中注释掉了缓存内容,可以在这里找到: https : //github.com/jValdron/heroku-buildpack-nodejs

Here is an output of the push: http://pastebin.com/L3Yqy2NR 这是推送的输出: 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. 另外,当我从package.json中删除了一些依赖项时,如果我使用“ heroku run bash”登录,则可以看到那些已删除的依赖项在node_modules中。 I already tried to remove the node_modules folder and do another 'git push', that didn't work either. 我已经尝试删除node_modules文件夹并执行另一个“ git push”,但这也不起作用。 And those removed deps are still in node_modules. 那些删除的部门仍然在node_modules中。

Anyone have an idea on how to fix this? 有人对如何解决这个问题有想法吗?

EDIT: 编辑:

Here is my package.json file: 这是我的package.json文件:

{
    "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. 如前所述,猫鼬设置为3.6.0rc。 Mpath is a dependencies in Mongoose's package.json file. Mpath是Mongoose的package.json文件中的依赖项。 If I look at my local mongoose package.json file, I can see this: 如果查看本地的mongoose package.json文件,可以看到以下内容:

"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. 另外,如果我使用heroku run bash登录,请heroku run bash ,然后导航到node_modules/mongoose/node_modules我会发现mpath和mpromise不存在。

node_modules was in the Git repo. node_modules在Git仓库中。 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支持为node_modules禁用缓存: https ://devcenter.heroku.com/articles/nodejs-support#cache-behavior

Heroku maintains a cache directory that is persisted between builds. Heroku维护一个缓存目录,该目录在构建之间保持不变。 This cache is used to store caches for npm, yarn, and bower. 该缓存用于存储npm,yarn和bower的缓存。 You can disable all caching for Node.js apps if you prefer: 如果愿意,可以禁用Node.js应用程序的所有缓存:

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 您需要将package.json更新为您正在使用的最新版本的猫鼬

you will need to add mpath to your package.json also (before the mongoose entry) 您还需要将mpath添加到package.json(在猫鼬条目之前)

can you post your package.json file? 您可以发布您的package.json文件吗?

Remove cache of node_modules and redeploy it: 删除node_modules的缓存并重新部署:

git rm -r --cached node_modules

and then git push heroku master 然后git push heroku master

You can also disable the cache if you don't want cache node_module while re-deploying: 如果在重新部署时不希望缓存node_module,则也可以禁用缓存:

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. 更改package.json中的Node版本对我有用。

For example: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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