Heroku Deploy Error: Cannot find module './err

2019-02-20 05:09发布

问题:

I built my app using yeoman angular-fullstack generator and then modified for my own purposes. I built the dist folder to deploy to heroku using yo angular-fullstack:deploy heroku. It creates a new heroku app for me and when I cd into the dist folder and git push heroku master everything works great.

I want to be able to add my existing heroku app to the deployment process for this dist folder so I followed this post How to link a folder with an existing Heroku app. I'm able to then deploy to my own app with a different remote name than heroku.

I keep getting the same error when it starts to run on heroku. I can't figure out why the exact same code runs fine on the app created for me but not my existing app. It's almost like I need to clear the node_modules and push again?

    2014-02-21T04:43:51.989439+00:00 app[web.1]: module.js:340
    2014-02-21T04:43:51.996351+00:00 app[web.1]: Error: Cannot find module './errors/cast'
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:338:15)
    2014-02-21T04:43:51.991555+00:00 app[web.1]:     throw err;
    2014-02-21T04:43:51.991785+00:00 app[web.1]:           ^
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at require (module.js:380:17)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Module.require (module.js:36         4:17)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Function.Module._load (module.js:280:25)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Module._compile (module.js:456:26)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Function.Module._load (module.js:312:12)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Object.<anonymous> (/app/node_modules/mongoose/lib/error.js:32:27)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Module.load (module.js:356:32)
    2014-02-21T04:43:51.996351+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:474:10)
    2014-02-21T04:43:51.996560+00:00 app[web.1]:     at Module.require (module.js:364:17)
    2014-02-21T04:43:53.457214+00:00 heroku[web.1]: State changed from starting to crashed

Here is my packages.json from the dist folder

   {
       "name": "myapp",
       "version": "1.0.0",
       "dependencies": {
         "express": "~3.4.3",
         "lodash": "~2.4.1",
         "mongoose": "~3.5.5",
         "mongoose-unique-validator": "~0.3.0",
         "connect-mongo": "~0.4.0",
         "passport": "latest",
         "passport-local": "latest",
         "passport-facebook": "latest",
         "passport-twitter": "latest",
         "passport-google": "latest",
         "ejs": "~0.8.4"
       },
       "engines": {
         "node": ">=0.10.0"
        },
        "scripts": {
          "test": "grunt test"
        }
      }

回答1:

The issue is almost certainly that you haven't checked in all the files you need. If you can't see the problem in your git repository, try running heroku run bash and using cd, ls, and more to look around what's getting deployed to Heroku and see what is missing.

Your problem is likely that you have require('./errors/cast') but have not checked in a cast file.

Update:

The other likelihood is that you checked in ./errors/Cast on OS X which is case insensitive, but the file can't be found on Linux which is case sensitive.