Argon2 Issue with Node.js Docker Container on Windows

  docker, node.js, npm

I have a Node.js application that runs perfectly inside a Docker container in a Linux environment and now I need to run on my Windonws machine. But I’m having a problem with Argon2, which keeps returning an error, and I’ve tried several ways to solve it.

Below is the error that keeps returning.

[2:29:32 PM] Starting compilation in watch mode...
application    |
application    | [2:31:27 PM] Found 0 errors. Watching for file changes.
application    |
application    | internal/modules/cjs/loader.js:1131
application    |   return process.dlopen(module, path.toNamespacedPath(filename));
application    |                  ^
application    |
application    | Error: Error loading shared library /usr/src/app/node_modules/argon2/lib/binding/napi-v3/argon2.node: Exec format error
application    |     at Object.Module._extensions..node (internal/modules/cjs/loader.js:1131:18)
application    |     at Module.load (internal/modules/cjs/loader.js:937:32)
application    |     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
application    |     at Module.require (internal/modules/cjs/loader.js:961:19)
application    |     at require (internal/modules/cjs/helpers.js:92:18)
application    |     at Object.<anonymous> (/usr/src/app/node_modules/argon2/argon2.js:9:56)
application    |     at Module._compile (internal/modules/cjs/loader.js:1072:14)
application    |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
application    |     at Module.load (internal/modules/cjs/loader.js:937:32)
application    |     at Function.Module._load (internal/modules/cjs/loader.js:778:12)

I have the file .dockerignore, which looks like this.

.git
docker-compose.yml
.env.example
.gitlab-ci.yml
Makefile
.vscode
tmp
_Production

# Log files
npm-debug.log*

# Dependency directories
node_modules
/node_modules
npm-debug.log

# Coverage files
coverage
.nyc_output

# Documentation files
/docs
README.md
Insomnia
.scannerwork

Dockerfile

FROM node:14-alpine as development

WORKDIR /usr/src/app

COPY package*.json ./

COPY . .

RUN npm install -g @nestjs/cli && npm install

RUN npm run build

FROM node:14-alpine as production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

COPY --from=development /usr/src/app/package*.json ./
COPY --from=development /usr/src/app/dist ./dist

RUN npm ci

CMD ["node", "dist/main"]

Dockerfile.prod

FROM node:14-alpine as development

WORKDIR /usr/src/app

COPY package*.json ./

COPY . .

RUN npm install -g @nestjs/cli && npm install

RUN npm run build

FROM node:14-alpine as production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/src/app

COPY --from=development /usr/src/app/package*.json ./
COPY --from=development /usr/src/app/dist ./dist

RUN npm ci

CMD ["node", "dist/main"]

docker-compose.yml

version: '3.7'

services:
  application:
    container_name: application
    build:
      context: .
      target: development
    volumes:
      - .:/usr/src/app
    ports:
      - ${APP_PORT}:${APP_PORT}
      # - 9229:9229
    command: npm run start:dev
    env_file:
      - .env
    depends_on:
      - database

  database:
    image: mysql:5.7
    container_name: database
    command:
      [
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_unicode_ci',
      ]
    environment:
      - MYSQL_DATABASE=${DB_DATABASE}
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
    ports:
      - 33306:3306
    volumes:
      - database-data:/var/lib/mysql

volumes:
  database-data:
    driver: 'local'

networks:
  default:
    external:
      name: dev

Source: Docker Questions

LEAVE A COMMENT