Cloud Run Container Failed To Start - node.js

I am using Cloud Run and I got an error when deploying to Cloud Run. It says Container failed to start.
Node.js Version: 16.13.2
Error:
/usr/src/app/node_modules/.bin/../node/bin/node: 1: /usr/src/app/node_modules/.bin/../node/bin/node: This: not found
Docker File:
FROM node:16-slim
WORKDIR /usr/src/app
COPY package.json package*.json ./
RUN npm install --only=production
COPY . .
CMD [ "npm", "start" ]
package.json:
{
"name": "something-name",
"version": "1.0.0",
"description": "something-description",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "JacTBB",
"license": "ISC",
"dependencies": {
"#google-cloud/firestore": "^5.0.2",
"discord-webhook-node": "^1.1.8",
"dotenv": "^10.0.0",
"express": "^4.17.2",
"express-rate-limit": "^5.5.1",
"noblox.js": "^4.12.0",
"node": "^16.3.2",
"node-fetch-npm": "^2.0.4",
"npm": "^8.3.2"
}
}

I just deleted my node_modules folder and reinstalled everything. Works now.

Related

Error during uploading mern stack project into heroku

In Procfile:
web: node Backend/server.js
In package.json of backend, I am using post build for react app. its saying cannot find module /app/backend/server.js.
{
"name": "ecommerce",
"version": "1.0.0",
"description": "",
"main": "Backend/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node backend/server.js",
"dev": "nodemon backend/server.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false && npm install --prefix frontend && npm run build --prefix frontend"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cloudinary": "^1.28.1",
"cookie-parser": "^1.4.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.10",
"nodemailer": "^6.7.0",
"nodemon": "^2.0.13",
"stripe": "^8.197.0",
"validator": "^13.6.0"
}
}
My project is laid out like this:
Backend/
frontend/
Procfile
package-lock.json
package.json
Your start script tries to run node backend/server.js, but your file is actually at Backend/server.js. Heroku's filesystem is case-sensitive. You can use either option, but you must be consistent.
Here is one solution. Rename your directory:
git mv Backend backend
And update your Procfile:
web: node backend/server.js
Then commit and redeploy.

sh: 1: nodemon: not found on Docker compose

I am having serious issues setting up docker. When I run sudo docker-compose up -d and sudo docker-compose logs -f my app is logging sh: 1: nodemon: not found over and over again. The problem is that I don't even have nodemon anymore : /
If I run the exact same project with npm start and manually turn on mysql it works.
My dockerfile:
FROM node:latest
# Create app directory
WORKDIR ./
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
#WORKDIR /node_modules
RUN npm ci --only=production
RUN npm install
# Bundle app source
COPY . .
EXPOSE 8003
CMD [ "npm", "start" ]
My package.json:
{
"name": "name",
"version": "6.4",
"description": "sdasdsadsad",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node --inspect=0.0.0.0 app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.25.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.5",
"dotenv": "^10.0.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"express-flash": "^0.0.2",
"express-flash-messages": "^0.1.1",
"express-formidable": "^1.2.0",
"express-mysql-session": "^2.1.7",
"express-session": "^1.17.2",
"express-validator": "5.3.1",
"helmet": "^4.6.0",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.3",
"mysql": "^2.18.1",
"mysql-pool-booster": "^1.0.3",
"node-lame": "^1.3.2",
"nodemailer": "^6.7.0",
"sharp": "^0.29.1",
"uglify-js": "^3.14.5",
"uglifycss": "^0.0.29",
"util.promisify": "^1.1.1"
}
}
My docker-compose and package-lock.json also don't contain nodemon anymore...
Delete package lock file and Try using this command to rebuild the container.
sudo docker-compose up -d --build

Can't Dockerize my simple typescript website

I am trying to get a Typescript project running in Docker. I created the Docker file based on a tutorial but when I run it I get:
/usr/local/bin/docker-entrypoint.sh: 8: exec: .: Permission denied
I am not sure how to diagnosis this problem.
I can enter the container with
docker run --rm -it d3ca97c88aec bash -il
and run the server with
npm start
I have no file called docker-entrypoint.sh and I didn't make one.
I STRONGLY FEEL THIS IS BECAUSE TYPESCRIPT MAKES A BUILD FOLDER AND THAT BUILD FOLDER IS PERMISSIONED DIFFERENTLY.
Dockerfile
FROM node:12
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
ENV COUCH_URL=NotSafeForStackOverflow
RUN npx tsc
EXPOSE 8080
CMD npx ts-node index.ts
{
"name": "express-react-app",
"version": "1.0.0",
"main": "index.js",
"repository": "",
"author": "",
"license": "",
"private": null,
"dependencies": {
"agentkeepalive": "^4.1.3",
"apollo-utilities": "^1.3.4",
"base64-arraybuffer": "^0.2.0",
"express": "^4.17.1",
"express-graphql": "^0.11.0",
"graphql": "^15.3.0",
"graphql-depth-limit": "^1.1.0",
"graphql-tag": "^2.11.0",
"graphql-type-json": "^0.3.2",
"i": "^0.3.6",
"merge-graphql-schemas": "^1.7.8",
"nano": "^8.2.2",
"node-webcrypto-ossl": "^2.1.1",
"npm": "^6.14.8",
"text-encoding": "^0.7.0",
"ts-node": "^9.0.0",
"typescript": "^3.7.4",
"uuid": "^8.3.0"
},
"scripts": {
"start": "npx ts-node index.ts",
"build": "npx tsc",
"dev": "nodemon --watch '**/*.ts' --exec 'ts-node' index.ts"
},
"devDependencies": {
"#types/express": "^4.17.7",
"#types/graphql": "^14.5.0",
"#types/node": "^14.6.3"
}
}
when you run CMD npx ts-node index.ts
it will overwrite default CMD [ "node" ]
please refer link below to how to use node image :
https://github.com/nodejs/docker-node/blob/master/README.md#how-to-use-this-image
you shoud be able done by using docker-compose :
version: "2"
services:
node:
image: "node:8"
user: "node"
working_dir: /home/node/app
environment:
- NODE_ENV=production
volumes:
- ./:/home/node/app
expose:
- "8081"
command: "npm start"

Build node.js app using yarn but getting error Command "build" not found

This is my package.json file.
{
"name": "moneymall",
"version": "1.0.0",
"description": "A money mall server app.",
"main": "index.js",
"author": "Anbu Selvan",
"license": "ISC",
"keywords": [],
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"e": "0.0.4",
"express": "^4.16.4",
"mysql": "^2.16.0",
"pug": "^2.0.3",
"yarn": "^1.15.2"
},
"devDependencies": {
"nodemon": "^1.18.10",
"react-scripts": "^2.1.8"
}
}
Run yarn build and get this error.
yarn run v1.15.2 error Command "build" not found. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command
You don't seem to have a script.build key defined in your package.json file. Sample entry for building with webpack library would be:
"scripts": {
"build": "webpack"
}
If you execute yarn run it will show the list of commands which can be run.
Ideally yarn run dev will do the trick of compiling the build
Please re-read the yarn documentation. You don't seem to have a script key declaring what you build script is, and thus Yarn does not know what to load.

Please install sqlite3 package manually after electron-packager on linux for windows

I am trying to package my app with electron-packager. My app have as dependencies sqlite3 and sequelize.
here is my package.json file :
{
"name": "electronjs_base",
"version": "1.0.0",
"description": "Projet de base Electron JS",
"main": "main.js",
"scripts": {
"start": "electron main.js",
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "install-app-deps",
"rebuild": "electron-rebuild -f -w sqlite3"
},
"author": "Aurélien Colombet & Steven Servanton",
"license": "ISC",
"devDependencies": {
"electron": "^4.0.3",
"electron-builder": "^20.38.5",
"electron-packager": "^13.0.1",
"electron-rebuild": "^1.8.2"
},
"dependencies": {
"cors": "^2.8.5",
"ejs": "^2.6.1",
"electron-reload": "^1.4.0",
"express": "^4.16.4",
"formidable": "^1.2.1",
"fs": "0.0.1-security",
"path": "^0.12.7",
"sequelize": "^4.42.0",
"sqlite3": "^4.0.6"
}
}
I am on linux and I am trying to build my app for windows. I use electron-packager for that, with that command :
electron-packager . gamemaster_interface --overwrite --platform=win32 --arch=x64 --out=release-builds
My app works well on linux when I launch it with npm run start, but when I am trying to run it on windows with the executable file created by electron-packager I have a javascript error :
I don't know how to solve that problem, I have trying multiple things like adding sqlite3 in devDependencies instead of dependencies in the package.json but I still have the error.
Thank you for reading me and I hope someone have the solution :).
Have a nice day !

Resources