Error: #prisma/client did not initialize yet. Please run "prisma generate" - node.js

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 | > express#0.0.0 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

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

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

Related

How to using docker-compose with environment

I have node application that build into an image. This image not contain .env file because I add it on .gitignore whereas the application need it. How can I configure this environment on docker-compose?
I've read some of example but still dont get it. This question has same problem with me but it still doesn't work.
docker-compose:
version: "3.7"
services:
node:
container_name: node-app
image: node_app:latest
ports:
- 3334:3333
environment:
- HOST=127.0.0.1
- PORT=3333
- NODE_ENV=dummy
- APP_NAME=AdonisJs
- CACHE_VIEWS=false
- DB_CONNECTION=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_USER=root
- DB_PASSWORD=password
- DB_DATABASE=database
Dockerfile:
FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i -g #adonisjs/cli
RUN npm install
ENV HOST=0.0.0.0
COPY . .
EXPOSE 3333
CMD [ "node", "server.js" ]
Everytime I run docker-compose up its ended up with this.
WARNING: The HOST variable is not set. Defaulting to a blank string.
WARNING: The PORT variable is not set. Defaulting to a blank string.
Recreating node-app_node_1 ... done
Attaching to node-app_node_1
node_1 |
node_1 | Error: ENOENT: no such file or directory, open '/usr/src/app/.env'
node_1 |
node_1 |
node_1 | 1 Env.load
node_1 | /usr/src/app/node_modules/#adonisjs/framework/src/Env/index.js:110
node_1 |
node_1 | 2 new Env
node_1 | /usr/src/app/node_modules/#adonisjs/framework/src/Env/index.js:42
node_1 |
node_1 | 3 Object.closure
node_1 | /usr/src/app/node_modules/#adonisjs/framework/providers/AppProvider.js:29
node_1 |
node_1 | 4 Ioc._resolveBinding
node_1 | /usr/src/app/node_modules/#adonisjs/fold/src/Ioc/index.js:231
node_1 |
node_1 | 5 Ioc.use
node_1 | /usr/src/app/node_modules/#adonisjs/fold/src/Ioc/index.js:731
node_1 |
node_1 | 6 AppProvider.boot
node_1 | /usr/src/app/node_modules/#adonisjs/framework/providers/AppProvider.js:337
node_1 |
node_1 | 7 anonymous
node_1 | /usr/src/app/node_modules/#adonisjs/fold/src/Registrar/index.js:147
node_1 |
node_1 | 8 arrayMap
node_1 | /usr/src/app/node_modules/lodash/lodash.js:653
node_1 |
node-app_node_1 exited with code 1
All I know that docker-compose environment pass to the variable that called just as same as we define to get the value, but there is not .env file on the image to called the variable. What I have to do to make the docker-compose can pass the environment to the app? Any suggestion will be appreciated.
ENOENT indicates that node is looking for a file at /usr/src/app/.env but there is nothing there. Try adding
RUN touch /usr/src/app/.env
to your Dockerfile and see if having an empty .env file fixes it.

Strapi develop script not working with PM2

I am trying to run Strapi in development mode with pm2 by using this command:
pm2 start npm --name myprojectname -- run develop
Unfortunately, I get the following error
0|edtech-a | SyntaxError: Unexpected token ':'
0|edtech-a | at wrapSafe (internal/modules/cjs/loader.js:979:16)
0|edtech-a | at Module._compile (internal/modules/cjs/loader.js:1027:27)
0|edtech-a | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|edtech-a | at Module.load (internal/modules/cjs/loader.js:928:32)
0|edtech-a | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
0|edtech-a | at Object.<anonymous> (C:\Users\dimit\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
0|edtech-a | at Module._compile (internal/modules/cjs/loader.js:1063:30)
0|edtech-a | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|edtech-a | at Module.load (internal/modules/cjs/loader.js:928:32)
0|edtech-a | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
PM2 version is 4.5.1
NodeJS version is 14.15.4
NPM version is 6.13.2
Strapi version is 3.1.0-alpha.5
I get the same error when I try to run Strapi in development mode through an ecosystem.config.json file as well.
Has somebody faced this issue, if yes, how can I solve it?
Yeah, I encountered some problems myself and decided to go for a workaround:
Create a script with the commands you would type normally:
touch strapi.sh
Type in your desired commands:
nano strapi.sh
cd my-strapi-project
npm run develop
Close and save (Crtl+x then type "y" and press enter).
Now just start that file with pm2
pm2 start strapi.sh
Check if everything works fine
pm2 logs
Thats it.
Can you try with this:
pm2 start npm --name myprojectname --interpreter bash -- run develop
UPDATED
for yarn
pm2 start yarn --name myprojectname --interpreter bash -- run develop

"Failed to load gRPC binary module" error when running a Sails.js application inside a Docker container

I have a local Docker developer environment to build a Sails.js application. This is what my Dockerfile looks like:
FROM node:8.12
LABEL Name=us.gcr.io/my-project/my-app Version=1.0.0
# Container configuration
RUN npm install -g sails#1.0.2 grunt#1.0.3 nodemon#1.18.4
WORKDIR /usr/src/app
COPY ./server/package.json ./package.json
RUN npm install
VOLUME /usr/src/app
EXPOSE 1337
This is what my docker-compose.yml file looks like:
version: '3.4'
services:
server:
image: us.gcr.io/my-project/my-app:latest
build: .
environment:
NODE_ENV: development
IS_DEV_MACHINE: "yes"
ports:
- 1338:1337 # HOST_PORT is 1339 to avoid conflicts with other Sails.js apps running on host
volumes:
- ./server:/usr/src/app
entrypoint: nodemon
mongodb:
image: mongo:4
ports:
- 27018:27017 # HOST_PORT is 27018 to avoid conflicts with other MongoDB databases running on host
volumes:
- ../database:/data/db
Normally, everything works fine however, I recently imported and initialised the #google-cloud/logging NPM package in my application and now, when I run docker-compose up, I get the following error:
server_1 | error: Bootstrap encountered an error: (see below)
server_1 | error: Failed to lift app: { Error: Failed to load gRPC binary module because it was not installed for the current system
server_1 | Expected directory: node-v57-linux-x64-musl
server_1 | Found: [node-v57-darwin-x64-unknown]
server_1 | This problem can often be fixed by running "npm rebuild" on the current system
server_1 | Original error: Cannot find module '/usr/src/app/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-musl/grpc_node.node'
server_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/grpc_extension.js:53:17)
server_1 | at Module._compile (module.js:653:30)
server_1 | at Object.Module._extensions..js (module.js:664:10)
server_1 | at Module.load (module.js:566:32)
server_1 | at tryModuleLoad (module.js:506:12)
server_1 | at Function.Module._load (module.js:498:3)
server_1 | at Module.require (module.js:597:17)
server_1 | at require (internal/module.js:11:18)
server_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client_interceptors.js:145:12)
server_1 | at Module._compile (module.js:653:30)
server_1 | at Object.Module._extensions..js (module.js:664:10)
server_1 | at Module.load (module.js:566:32)
server_1 | at tryModuleLoad (module.js:506:12)
server_1 | at Function.Module._load (module.js:498:3)
server_1 | at Module.require (module.js:597:17)
server_1 | at require (internal/module.js:11:18) code: 'MODULE_NOT_FOUND' }
mongodb_1 | 2018-10-09T09:27:52.521+0000 I NETWORK [conn4] end connection 172.19.0.2:48730 (0 connections now open)
In the error above, "Bootstrap" is the bootstrap.js file in my Sails.js project that initialises #google-cloud/logging. This is how I am initialising the logger in bootstrap.js:
// Globally required packages
const { Logging } = require('#google-cloud/logging');
const logging = new Logging({ projectId: 'my-project' });
const logger = logging.log('test');
I just can't seem to figure out why this error is occurring. I even tried changing my base Docker image to the official Google App Engine Docker image (gcr.io/google-appengine/nodejs) and that did not help either. i can't find any solutions to this problem anywhere. Appreciate any help.
By any chance did you do a npm install on your local Mac (darwin) environment when it should have been done in the container (linux)? The grpc binary is for the wrong OS thus the error. This often happens with a local Mac running a linux Docker container.
Expected directory: node-v57-linux-x64-musl
Found: [node-v57-darwin-x64-unknown]
The solution would be to rm -fr node_modules and do npm install in the container.
Rebuild the app by the following command.
npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=musl
It looks like the project is having difficulty finding dependencies such as the gRPC binary module (repaired with npm install grpc) or perhaps where they are currently located - more info here

Learning NodeJS & MongoDB Docker compose

I have a NodeJS project that uses MongoDB. I would like to run this service in a Docker container, but despite the many examples I have based my learning from, this will not work.
Here is my /heimdall_jwt/Dockerfile:
FROM node:9-alpine
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
RUN npm install pm2 -g
COPY . /usr/src/app
EXPOSE 3000
CMD ["pm2-docker", "start", "process.json"]
And here is my /heimdall_jwt/docker-compose.yml
version: '2'
# Define the services/containers to be run
services:
myapp: #name of your service
build: ./ # specify the directory of the Dockerfile
ports:
- "3000:3000" #specify ports forwarding
links:
- database # link this service to the database service
volumes:
- .:/usr/src/app
depends_on:
- database
database: # name of the service
image: mongo # specify image to build container from
I tried running via: $docker-compose up --build
which results in the mongo being build and starting. Here is the condensed output:
Building myapp
Step 1/8 : FROM node:9-alpine
...
Step 4/8 : RUN npm install
---> Using cache
---> befb91b1324c
...
Removing intermediate container 945eb0ad40d5
Successfully built b500f7ec9b89
Successfully tagged heimdalljwt_myapp:latest
Creating heimdalljwt_database_1 ...
Creating heimdalljwt_database_1 ... done
Creating heimdalljwt_myapp_1 ...
Creating heimdalljwt_myapp_1 ... done
Attaching to heimdalljwt_database_1, heimdalljwt_myapp_1
database_1 | 2017-11-25T21:15:39.001+0000 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
database_1 | 2017-11-25T21:15:39.002+0000 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
database_1 | 2017-11-25T21:15:39.003+0000 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
database_1 | 2017-11-25T21:15:39.005+0000 I NETWORK [thread1] waiting for connections on port 27017
myapp_1 | 0|heimdall | Error: Cannot find module 'bcryptjs'
myapp_1 | 0|heimdall | at Function.Module._resolveFilename (module.js:542:15)
myapp_1 | 0|heimdall | at Function.Module._load (module.js:472:25)
myapp_1 | 0|heimdall | at Module.require (module.js:585:17)
myapp_1 | 0|heimdall | at require (internal/module.js:11:18)
myapp_1 | 0|heimdall | at Object.<anonymous> (/usr/src/app/user/User.js:2:14)
myapp_1 | 0|heimdall | at Module._compile (module.js:641:30)
myapp_1 | 0|heimdall | at Object.Module._extensions..js (module.js:652:10)
myapp_1 | 0|heimdall | at Module.load (module.js:560:32)
myapp_1 | 0|heimdall | at tryModuleLoad (module.js:503:12)
myapp_1 | 0|heimdall | at Function.Module._load (module.js:495:3)
myapp_1 | 0|heimdall | at Module.require (module.js:585:17)
myapp_1 | 0|heimdall | at require (internal/module.js:11:18)
myapp_1 | 0|heimdall | at Object.<anonymous> (/usr/src/app/user/UserController.js:12:12)
myapp_1 | 0|heimdall | at Module._compile (module.js:641:30)
myapp_1 | 0|heimdall | at Object.Module._extensions..js (module.js:652:10)
myapp_1 | 0|heimdall | at Module.load (module.js:560:32)
myapp_1 | PM2 | App name:heimdall_app id:0 disconnected
I am uncertain what is going on here, but I am guessing that the dependencies are either not being installed, or not being copied into the working directory. How
UPDATED
Modified from original posting as I still am struggling to get this to work.
You should copy files after npm install. Right now you are installing dependencies and then copying over everything, so you are effectively canceling that install and you don't have dependencies.
In your Dockerfile you have:
...
RUN npm install
RUN npm install pm2 -g
COPY . /usr/src/app
...
It should be:
...
COPY . /usr/src/app
RUN npm install
RUN npm install pm2 -g
...

Cannot find module 'express'

I'm using docker-compose to run node.js express app.
this is my Dockerfile
FROM node:latest
MAINTAINER jorge#valeet.io
# set default workdir
WORKDIR /src/api
# Expose the application port and run application
EXPOSE 3015
CMD [ "node" , "app.js"]
docker-compose.yml
api:
build: .
volumes:
- .:/src/api
- /src/api/node_modules
links:
- mongo
ports:
- "3015:3015"
mongo:
image: mongo:3.2
ports:
- "27017:27017"
running:
docker-compose build
docker-compose up -d
I get an error on the the node.js app
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/src/api/app.js:4:15)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
I tried reinstall express, delete all packages, adding node_modules as volume in the docker-compose (the actual setup). I don't know what else to do.
I'm running it on a mac just in case it matters
Thanks!

Resources