简体   繁体   中英

Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

I am trying to deploy my REST API to heroku. However, the application is not working. In the application log, i got this

Process exited with status 1
2019-09-23T01:09:55.744676+00:00 heroku[web.1]: Starting process with command `node server.js`
2019-09-23T01:09:58.446510+00:00 heroku[web.1]: Process exited with status 1
2019-09-23T01:09:58.468276+00:00 heroku[web.1]: State changed from starting to crashed
2019-09-23T01:09:58.370869+00:00 app[web.1]: internal/modules/cjs/loader.js:807
2019-09-23T01:09:58.370888+00:00 app[web.1]: return process.dlopen(module, path.toNamespacedPath(filename));
2019-09-23T01:09:58.370890+00:00 app[web.1]: ^
2019-09-23T01:09:58.370892+00:00 app[web.1]: 
2019-09-23T01:09:58.370894+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2019-09-23T01:09:58.370896+00:00 app[web.1]: at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
2019-09-23T01:09:58.370898+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-09-23T01:09:58.370900+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-09-23T01:09:58.370902+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-09-23T01:09:58.370904+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-09-23T01:09:58.370906+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-09-23T01:09:58.370909+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2019-09-23T01:09:58.370910+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-09-23T01:09:58.370912+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-09-23T01:09:58.370915+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-09-23T01:09:58.370917+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-09-23T01:09:58.370919+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-09-23T01:09:58.370921+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-09-23T01:09:58.370923+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-09-23T01:09:58.370924+00:00 app[web.1]: at Object.<anonymous> (/app/routes/auth.js:6:16)
2019-09-23T01:09:58.370926+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)

This seems to have something to do with bcrypt module. I tried the solutions suggested here: https://github.com/kelektiv/node.bcrypt.js/issues/595 and https://github.com/kelektiv/node.bcrypt.js/issues/635

such as: npm rebuild bcrypt --build-from-source

here is package.json file:

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^3.0.6",
    "body-parser": "^1.18.3",
    "cors": "^2.8.4",
    "cron": "^1.7.2",
    "express": "^4.16.3",
    "jsonwebtoken": "^8.3.0",
    "jwt-simple": "^0.5.6",
    "mapnik": "^4.3.1",
    "mkdirp": "^0.5.1",
    "mongoose": "^5.7.1",
    "multer": "^1.4.1",
    "nodemailer": "^6.3.0",
    "request": "^2.88.0",
    "ug": "0.0.8"
  }
}

None of those solutions worked for me? How can I solve this problem?

I had the same issue, but with Docker. Turns out the node_modules folder was being uploaded. Make sure to add node_modules to your.gitignore (and/or.dockerignore)

Make.gitignore file. Run below commands in your terminal

git rm -r --cached node_modules

git commit -am "node_modules be gone!"

git push origin main

deploy to Heroku through GitHub or CLI

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