2

I am having a problem with my nodeJS back-end. I want to create a docker compose environment but I keep getting this error when I try to start my Prisma NodeJS app. I already tried lots of things and I can't find any usable solutions on Google. The application works without docker.

Docker compose file:

  endbit-express:
    container_name: endbit-express
    build: ./endbit-express
    volumes:
      - ./endbit-express:/app
      - /app/node_modules
    ports:
      - 8080:8080
    depends_on:
      - mysql
    environment:
      - DATABASE_URL=mysql://root:root@localhost:3306/endbit
    networks:
      - endbit

  mysql:
    container_name: endbit-mysql
    image: mysql:8.0.28
    restart: always
    ports:
      - 6033:3306
    environment:
      - MYSQL_DATABASE=endbit
      - MYSQL_ROOT_PASSWORD=root
    volumes:
      - dbdata:/var/lib/mysql
    networks:
      - endbit

Docker file:

FROM node:17.4.0

WORKDIR /app

COPY package*.json ./
COPY prisma ./prisma

RUN npm install

COPY . .

RUN prisma generate

EXPOSE 8080

CMD ["npm", "start"]

Error:

endbit-express  | > [email protected] start
endbit-express  | > node ./bin/www
endbit-express  |
endbit-express  | /app/node_modules/.prisma/client/index.js:3
endbit-express  |     throw new Error(
endbit-express  |     ^
endbit-express  |
endbit-express  | Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
endbit-express  | In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues
endbit-express  |     at new PrismaClient (/app/node_modules/.prisma/client/index.js:3:11)
endbit-express  |     at Object.<anonymous> (/app/config/passport.js:7:16)
endbit-express  |     at Module._compile (node:internal/modules/cjs/loader:1097:14)
endbit-express  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
endbit-express  |     at Module.load (node:internal/modules/cjs/loader:975:32)
endbit-express  |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
endbit-express  |     at Module.require (node:internal/modules/cjs/loader:999:19)
endbit-express  |     at require (node:internal/modules/cjs/helpers:102:18)
endbit-express  |     at Object.<anonymous> (/app/app.js:7:1)
endbit-express  |     at Module._compile (node:internal/modules/cjs/loader:1097:14)
endbit-express  |
endbit-express  | Node.js v17.4.0
1
  • 1
    The volumes: mounts hide basically everything that the Dockerfile sets up; does deleting that block help? You will also run into connectivity problems since the Dockerfile won't be able to connect to the database (e.g., NestJS in Docker can't do a Prisma Migrate on Postgres in another Docker Container). If you can check the generated files into source control that might be the simplest approach. Commented Apr 5, 2022 at 22:22

2 Answers 2

3

Eventually I found the answer myself: I am using a docker compose file, and Docker doesn't recognize the localhost:3306 URL. In docker compose you need to link the containers by their name, so I changed the backend component environment with this (host = docker service name):

environment:
  - DB_HOST=mysql
  - DB_USER=root
  - DB_PASSWORD=root
  - DB_NAME=endbit-express
  - DB_PORT=3306
Sign up to request clarification or add additional context in comments.

Comments

2

add RUN npm i -g prisma before RUN prisma generate it should work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.