node.bcrypt.js icon indicating copy to clipboard operation
node.bcrypt.js copied to clipboard

invalid ELF header

Open darkdiesel opened this issue 1 year ago • 6 comments

Hello!

Before writing i searching the same issues but anyway not found a solution. :(

Used: "bcrypt": "^5.1.1", "@types/bcrypt": "^5.0.2", "@nestjs/core": "^10.3.10",

Node tested, node 20.17.0 (npm 10.8.2) node 21.7.3 (npm 10.5.0) node 22.5.1 (npm 10.8.3)

I used instruction from https://docs.nestjs.com/security/encryption-and-hashing site, but after starting dev or prod server i have an error:

    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1586:18)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/var/www/api.admin-panel.loc/node_modules/bcrypt/bcrypt.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1104:12)

full package.json

"dependencies": {
    "@fastify/static": "^7.0.4",
    "@nestjs-modules/mailer": "^2.0.2",
    "@nestjs/axios": "^3.0.2",
    "@nestjs/bull": "^10.1.1",
    "@nestjs/cache-manager": "^2.2.2",
    "@nestjs/common": "^10.3.10",
    "@nestjs/config": "^3.2.3",
    "@nestjs/core": "^10.3.10",
    "@nestjs/mapped-types": "*",
    "@nestjs/platform-express": "^10.3.10",
    "@nestjs/platform-fastify": "^10.3.10",
    "@nestjs/swagger": "^7.4.0",
    "axios": "^1.7.2",
    "bcrypt": "^5.1.1",
    "bull": "^4.15.1",
    "cache-manager": "^3.4.0",
    "cache-manager-redis-store": "^2.0.0",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "fastify": "^4.28.1",
    "mailgun.js": "^10.2.1",
    "mysql2": "^3.10.2",
    "node-mailjet": "^6.0.5",
    "nodemailer": "^6.9.14",
    "reflect-metadata": "^0.2.2",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.4.1",
    "@nestjs/schematics": "^10.1.2",
    "@nestjs/testing": "^10.3.10",
    "@types/bcrypt": "^5.0.2",
    "@types/cache-manager-redis-store": "^2.0.4",
    "@types/express": "^4.17.21",
    "@types/jest": "^29.5.12",
    "@types/mysql": "^2.15.26",
    "@types/node": "^20.14.9",
    "@types/nodemailer": "^6.4.15",
    "@types/supertest": "^6.0.2",
    "@typescript-eslint/eslint-plugin": "^7.15.0",
    "@typescript-eslint/parser": "^7.15.0",
    "eslint": "^8.57.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.1.3",
    "husky": "^9.0.11",
    "jest": "^29.7.0",
    "prettier": "^3.3.2",
    "source-map-support": "^0.5.21",
    "supertest": "^7.0.0",
    "ts-jest": "^29.1.5",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.5.3"
  },

darkdiesel avatar Aug 30 '24 09:08 darkdiesel

This usually happens if bcrypt.node is of a different OS/Arch than it was originally installed it

Are you running docker or some remote development environment?

recrsn avatar Aug 30 '24 10:08 recrsn

If you are working on Docker, you should ignore node_modules, this will solve your problem. If you are working with docker-compose, you probably mounted your application from the host (your root directory) to the container. This replaced the node_modules on the host with the node_modules inside docker.

docker-compose.yaml example

version: '3.9'

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
      target: development
    ports:
      - "3000:3000"
    env_file:
      - .env
    volumes:
      - ./:/app
      - /app/node_modules

docker example

docker run -d \
  -p 3000:3000 \
  --env-file .env \
  -v $(pwd):/app \
  -v /app/node_modules \
  --name api \
  your_image_name

veyselaksin avatar Sep 02 '24 14:09 veyselaksin

This usually happens if bcrypt.node is of a different OS/Arch than it was originally installed it

Are you running docker or some remote development environment?

Yes, using docker and sometimes vagrant with virtual box

darkdiesel avatar Sep 03 '24 11:09 darkdiesel

If you are working on Docker, you should ignore node_modules, this will solve your problem. If you are working with docker-compose, you probably mounted your application from the host (your root directory) to the container. This replaced the node_modules on the host with the node_modules inside docker.

docker-compose.yaml example

version: '3.9'

services:
  api:
    build:
      context: .
      dockerfile: Dockerfile
      target: development
    ports:
      - "3000:3000"
    env_file:
      - .env
    volumes:
      - ./:/app
      - /app/node_modules

docker example

docker run -d \
  -p 3000:3000 \
  --env-file .env \
  -v $(pwd):/app \
  -v /app/node_modules \
  --name api \
  your_image_name

Thanks will try today your solution

darkdiesel avatar Sep 03 '24 11:09 darkdiesel

Did you solve the problem?

veyselaksin avatar Sep 08 '24 09:09 veyselaksin

Thanks for helping me. For docker yes, but for vagrant still have an issue. Please, give some time and i will back with responce. Or maybe you have solution to solve for vagrant?

darkdiesel avatar Sep 19 '24 06:09 darkdiesel