了解Heroku在部署Nodejs应用程序时在日志中encryption错误

我正在尝试将我的node.js应用程序部署到Heroku。 它在本地工作完全正常,但是当我尝试部署它,我不断得到这个:

2017-12-12T17:32:18.220591+00:00 app[web.1]: > ev@1.0.0 start /app 2017-12-12T17:32:18.220592+00:00 app[web.1]: > node app.js 2017-12-12T17:32:18.220592+00:00 app[web.1]: 2017-12-12T17:32:18.898850+00:00 heroku[web.1]: Process exited with status 1 2017-12-12T17:32:18.910740+00:00 heroku[web.1]: State changed from starting to crashed 2017-12-12T17:32:18.819322+00:00 app[web.1]: module.js:664 2017-12-12T17:32:18.819338+00:00 app[web.1]: return process.dlopen(module, path._makeLong(filename)); 2017-12-12T17:32:18.819339+00:00 app[web.1]: ^ 2017-12-12T17:32:18.819339+00:00 app[web.1]: 2017-12-12T17:32:18.819340+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header 2017-12-12T17:32:18.819341+00:00 app[web.1]: at Object.Module._extensions..node (module.js:664:18) 2017-12-12T17:32:18.819342+00:00 app[web.1]: at Module.load (module.js:554:32) 2017-12-12T17:32:18.819342+00:00 app[web.1]: at tryModuleLoad (module.js:497:12) 2017-12-12T17:32:18.819343+00:00 app[web.1]: at Function.Module._load (module.js:489:3) 2017-12-12T17:32:18.819343+00:00 app[web.1]: at Module.require (module.js:579:17) 2017-12-12T17:32:18.819344+00:00 app[web.1]: at require (internal/module.js:11:18) 2017-12-12T17:32:18.819344+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16) 2017-12-12T17:32:18.819345+00:00 app[web.1]: at Module._compile (module.js:635:30) 2017-12-12T17:32:18.819345+00:00 app[web.1]: at Object.Module._extensions..js (module.js:646:10) 2017-12-12T17:32:18.819345+00:00 app[web.1]: at Module.load (module.js:554:32) 2017-12-12T17:32:18.819346+00:00 app[web.1]: at tryModuleLoad (module.js:497:12) 2017-12-12T17:32:18.819346+00:00 app[web.1]: at Function.Module._load (module.js:489:3) 2017-12-12T17:32:18.819346+00:00 app[web.1]: at Module.require (module.js:579:17) 2017-12-12T17:32:18.819347+00:00 app[web.1]: at require (internal/module.js:11:18) 2017-12-12T17:32:18.819347+00:00 app[web.1]: at Object.<anonymous> (/app/models/users.js:3:14) 2017-12-12T17:32:18.819347+00:00 app[web.1]: at Module._compile (module.js:635:30) 2017-12-12T17:32:18.827094+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2017-12-12T17:32:18.827465+00:00 app[web.1]: npm ERR! errno 1 2017-12-12T17:32:18.828807+00:00 app[web.1]: npm ERR! ev@1.0.0 start: `node app.js` 2017-12-12T17:32:18.828992+00:00 app[web.1]: npm ERR! Exit status 1 2017-12-12T17:32:18.829148+00:00 app[web.1]: npm ERR! 2017-12-12T17:32:18.829260+00:00 app[web.1]: npm ERR! Failed at the ev@1.0.0 start script. 2017-12-12T17:32:18.829357+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2017-12-12T17:32:18.834511+00:00 app[web.1]: 2017-12-12T17:32:18.834634+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 2017-12-12T17:32:18.834782+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-12-12T17_32_18_830Z-debug.log 

我已经做了npm安装和npm再次安装bcrypt,但错误仍然存​​在。 根据我对日志的理解,我认为这个错误与bcrypt有关吗?

这是我的package.json文件:

 { "name": "ev", "version": "1.0.0", "description": "search", "main": "app.js", "scripts": { "start": "node app.js", "test": "echo \"Error: no test specified\" && exit 1" }, "dependencies": { "bcrypt": "^1.0.3", "body-parser": "*", "express": "*", "jsonwebtoken": "^8.1.0", "mongoose": "*" }, "author": "My Name", "license": "ISC" 

你可以使用一个纯JS版本的bcrypt库。 像这样的东西

 https://github.com/dcodeIO/bcrypt.js 

这没有任何本地依赖,应该完美的工作。 我们在使用本地依赖到Heroku和其他云平台部署应用时遇到了很多困难,我们不得不将一些像bcrypt这样的库与纯js版本交换。