My Node app is running fine locally, but has run into an error when deploying to Heroku. The app uses Sequelize in a /models
folder, which contains index.js
, Company.js
and Users.js
. Locally, I am able to import the models using the following code in /models/index.js
:
// load models
var models = [
'Company',
'User'
];
models.forEach(function(model) {
module.exports[model] = sequelize.import(__dirname + '/' + model);
});
This works fine, however, when I deploy to Heroku the app crashes with the following error:
Error: Cannot find module '/app/models/Company'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at module.exports.Sequelize.import (/app/node_modules/sequelize/lib/sequelize.js:219:24)
at module.exports.sequelize (/app/models/index.js:60:43)
at Array.forEach (native)
at Object.<anonymous> (/app/models/index.js:59:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Process exited with status 8
Initially I thought it was due to case sensitivity (local mac vs heroku linux), but I moved the file, made a git commit, and then moved back and committed again to ensure Company.js
is capitalized in the git repository. This didn't solve the problem and I'm not sure what the issue could be.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…