Why my docker-compose.yml file not finding the package.json file? - reactjs

I am trying to dockerize my react/typecsript application, but when I try to docker-compose run frontend it does not find the package.json file. I do not have a DockerFile, only a docker-compose.yml
docker-compose.yml:
`version: '3.5'
services:
frontend:
image: node:latest
volumes:
- ./frontend:/app
ports:
- 3000:3000
working_dir: /app
command: bash -c "npm i && npm start"`
My root folder is called FULL-STACK-CHALLENGE and structure of my folder as follow:
Project structure(https://i.stack.imgur.com/RkCbY.png)
When I try to run the docker-compose.yml file give this error:
Creating full-stack-challenge_frontend_run ... done
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-01-12T17_30_41_901Z-debug-0.log
ERROR: 254
And I also want to open this application at localhost:3000
Where is the mistake I am making?
I already try to change the name of working_dir or the name of volumes and even try to create a DockerFile and nothing works

Related

When I enter command npm start it generates ENOENT error

I am new to ReactJs and firstly entered npx create-react-app my-app and after its installation, I entered npm start command. It says
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\Anonymous\OneDrive\Projects\react/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Anonymous\OneDrive\Projects\react\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
enter image description here
You should run the command in my-app folder, where you probably have a package.json file.
Navigate to the directory where package.json exist in your project which has been created by create-react-app. Then try to run npm start
if you are in same directory, then try to run npm cache clean, and after this npm start.

Cannot figure out working_directory syntax in yml file - React testing with CircleCI

I am trying to create a build environment for a react application but the save cache function can locate my package.json even though I have tried every possible combination of routes to help it locate it. this is my yml file:
jobs:
build:
docker:
-
image: "node:17.2.0"
steps:
- checkout
-
restore_cache:
keys:
- "v1-dependencies-{{ checksum \"package.json\" }}"
- v1-dependencies-
-
run: "npm install"
-
save_cache:
key: "v1-dependencies-{{ checksum \"package.json\" }}"
paths:
- ./node_modules
-
run: "npm test"
-
run: "npm build"
working_directory: ~/client
run:
docker:
-
image: "cimg/base:stable"
steps:
- checkout
-
run:
command: "echo Hello, World run!"
name: Run
version: 2.1
workflows:
run-workflow:
jobs:
- run
- build
My github structure is as follows:
.circleci (File)
--config.yml (This is where my yml file is)
client (File)
--package.json (This is where yml should find the package.json)
server (File
.gitignore
ReadMe.md
This is the error I get from CircleCI:
error computing cache key: template: cacheKey:1:19: executing "cacheKey" at <checksum "package.json">: error calling checksum: open /root/client/package.json: no such file or directory
Additionally:
#!/bin/bash -eo pipefail
npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /root/client/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/root/client/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-04-01T18_56_19_612Z-debug.log
Exited with code exit status 254
CircleCI received exit code 254

Getting this error while running npm start in terminal vs code

Getting this error while running npm start in terminal vs code:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\1 last try/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'D:\1 last try\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Acer\AppData\Local\npm-cache_logs\2021-12-13T12_38_55_514Z-debug.log
enter image description here
This error is likely due to a missing package.json file at your current directory. To create a new package.json in this directory, you can use npm init. It will prompt you for some metadata and automatically generate your package.json file.
I assume you are looking to run something similar to create-react-app based on the attempt to run the start script and the directory being named react-website-v1. In order to initialize a CRA site, the official documentation lists the commands for doing so as follows:
npx create-react-app my-app
cd my-app
npm start

docker compose doesn't detect package json

I created a dockerfile for frontend project and a docker compose project for the whole project. Running the frontend within a container works fine, however when I try with docker compose I always get the same error
Attaching to frontend_dev
frontend_dev | npm ERR! code ENOENT
frontend_dev | npm ERR! syscall open
frontend_dev | npm ERR! path /app/package.json
frontend_dev | npm ERR! errno -2
frontend_dev | npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
frontend_dev | npm ERR! enoent This is related to npm not being able to find a file.
frontend_dev | npm ERR! enoent
frontend_dev |
frontend_dev | npm ERR! A complete log of this run can be found in:
frontend_dev | npm ERR! /root/.npm/_logs/2021-01-10T22_25_43_776Z-debug.log
frontend_dev exited with code 254
The dockerfile in the frontend folder is like this
#pull base image
FROM node:13.12.0-alpine
#set working directory
WORKDIR /app
#install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install
#add frontend to docker container
COPY . ./
#launch frontend app
CMD [ "npm", "start" ]
and the docker-compose.yml is as this:
version: "3.0"
services:
frontend:
container_name: frontend_dev
build:
context: ./frontend
dockerfile: Dockerfile
volumes:
- /app/node_modules
- .:/app
ports:
- 3001:3000
stdin_open: true
environment:
- CHOKIDAR_USEPOLLING=true
and here is the structure of the project.project structre ,
docker-compose.yml is at the root of both frontend and backend, and just frontend contains the Dockerfile related to it.

Deploy AngularJS app into docker container

I am trying to deploy my angularjs app into a docker container:
myapp/web/Dockerfile
FROM node:latest
RUN mkdir /myapp
ADD . /myapp
WORKDIR /myapp
RUN npm install -g phantomjs-prebuilt
RUN npm install -g grunt-cli
RUN npm install -g grunt
RUN npm install -g bower
RUN npm install
RUN bower install --allow-root
RUN npm run v2
EXPOSE 9000
CMD ["grunt", "serve"]
myapp/docker-compose.yml
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
web:
build: ./web
image: myapp/web
environment:
- VIRTUAL_HOST=myapp.dev
Outputs
> phantomjs-prebuilt#2.1.14 install /usr/local/lib/node_modules/phantomjs-prebuilt
> node install.js
Considering PhantomJS found at /usr/local/bin/phantomjs
Looks like an `npm install -g`
Could not link global install, skipping...
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
Received 22866K total.
Extracting tar contents (via spawned process)
Removing /usr/local/lib/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1497270232242/phantomjs-2.1.1-linux-x86_64 -> /usr/ local/lib/node_modules/phantomjs-prebuilt/lib/phantom
Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-149727 0232242/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/lib/node_modules/phantomjs-prebuilt/lib/phantom'
errno: -13,
code: 'EACCES',
syscall: 'link',
path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1497270232242/phantomjs-2.1.1-linux-x86_64',
dest: '/usr/local/lib/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs- 2.1.1-linux-x86_64.tar.bz2-extract-1497270232242/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/lib/node_modules/phantomjs-prebuilt/lib/ph antom'
npm info lifecycle phantomjs-prebuilt#2.1.14~install: Failed to exec install script
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt#2.1.14 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs-prebuilt#2.1.14 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-06-12T12_23_56_471Z-debug.log
I tried to add USER root before the global npm install but nothing changes.
Any help apreciated
I have the same issue, and this works for me.
sudo npm install -g phantomjs#2.1.1 --unsafe-perm
https://github.com/Medium/phantomjs/issues/707#issuecomment-320989493

Resources