I have a nodejs application and I want to deploy it using docker.
I have the following structure for folders and files
/src
/config
status.js
role.js
index.js
/routes
user.routes.js
product.routes.js
index.js
index.js
Dockerfile
package.json
... other files and folders
the content of src/config/index.js is:
module.exports = {
...require("./status"),
...require("./role"),
};
The content of Dockerfile
FROM node:19-alpine3.16
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
CMD ["node", "src/index.js"]
when I do docker image build I got the following error
---> Running in 2f2e6c84845b
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /usr/src/app/src/config/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/src/config/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-12-26T09_17_19_235Z-debug-0.log
The command '/bin/sh -c npm i' returned a non-zero code: 254
I tried to add package.json with empty json to every folder has index.js file and that worked fine. but does that make sense to add package.json to every folder.
Related
D:\react> npm start
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\react/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'D:\react\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\Dell\AppData\Local\npm-cache_logs\2023-02-04T06_09_25_519Z-debug.log
I am a beginner , I have my node installed in C: drive but I Want to create a react project in D: drive . project was created but when I ran 'npm start' it gave me Error.
npm ERR! This is related to npm not being able to find a file.
Opened command prompt as an administrator and and changed my directories to d drive and reached to my folder . then created project and ran " npm start " from command prompt .it worked . so just I had to open project as an administrator.
follow below steps :
C:\Windows\system32>cd..
C:\Windows>cd..
C:\>d:
D:\>cd react
D:\react>npx create-react-app my-app
your project will be created. then go to project folder
D:\react>cd my-app
D:\react\my-app>npm start
// plz don't type above quotation mark.
now my project ran into the browser. I Hope it helps to others as well.
I have written a command line utility in JS which can be used to backup data to IPFS.
https://www.npmjs.com/package/ipfs-backup
When I am attempting to install it with npm install -g ipfs-backup I am getting an error which prevents the package from being installed.
The terminal is outputting the following:
npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path C:\Users\jwhit\AppData\Roaming\npm\node_modules\ipfs-backup\node index.js
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Users\jwhit\AppData\Roaming\npm\node_modules\ipfs-backup\node index.js'
npm ERR! enoent This is related to npm not being able to find a file.
The issue turned out to be that within my package.json file I had
"bin": {
"ipfs-backup": "node index.js",
"ipfs-restore": "node restore.js"
}
instead of
"bin": {
"ipfs-backup": "./index.js",
"ipfs-restore": "./restore.js"
}
It installs and functions correctly now.
---> Running in 0e34d471598d
> myproject#1.0.0 build /app
> node scripts/build.js
Could not find a required file.
Name: index.html
Searched in: /app/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myproject#1.0.0 build: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the myproject#1.0.0 build 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/2021-08-05T14_49_57_665Z-debug.log
The command '/bin/sh -c npm run build ;' returned a non-zero code: 1
##[error]The command '/bin/sh -c npm run build ;' returned a non-zero code: 1
##[error]The process '/usr/bin/docker' failed with exit code 1
So there is the error "can't find file" but actually THERE IS a public directory with the index.html file inside. I don't know why this is happening...
Edit: Im adding the docker file used in config pipe
# -- Base node --
FROM node:13.7-alpine AS build
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
ARG BUILD_ENV
RUN npm run build ;
# -- final build --
FROM nginx:1.17.8-alpine
COPY --from=build /app/build /var/www
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
I notice you are running this on docker, so you did wrong on docker during copy your react app directory to docker container.
You have not added your Dockerfile code here
So we suggest you to fix your dockerfile first. Also check your .dockerignore file and debug getting into docker container, if the directory exist there or not
So your docker file should be similar to this
COPY . ./
RUN npm run build
It should be like this (Not . /app):
# Copy other project files and build
COPY . ./
RUN npm run build
Why am I getting the following error when I run npm start in react?
C:\Users\ave\geekyShows>npm start
npm ERR! path C:\Users\ave\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\ave\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\ave\AppData\Roaming\npm-cache\_logs\2020-01-12T09_04_26_349Z-debug.log
The directory you're currently trying to run doesn't have a package.json file. Maybe you're outside of the project that you just created. Happens to me most of the time when I'm working in hurry. :D
You can just enter inside your project directory that has package.json file like so (Assuming your project name as geekyShows):
cd geekyShows
npm run start
Hope this helps.
So I've been trying to create a server for dynamic web pages using Openshift, so I created a bare-bones node.js/Express template just for connecting to Index.html (to test the code) but when I try and run the code Openshift goes into a crash loop back-off.
Note: I'm new to Node.js and back-end development in general so please be thorough with your answers.
The Openshift error log:
Environment:
DEV_MODE=false
NODE_ENV=production
DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using npm#3.10.9
npm info using node#v6.11.3
npm ERR! Linux 3.10.0-693.15.2.el7.x86_64
npm ERR! argv "/opt/rh/rh-nodejs6/root/usr/bin/node" "/opt/rh/rh-nodejs6/root/usr/bin/npm" "run" "-d" "start"
npm ERR! node v6.11.3
npm ERR! npm v3.10.9
npm ERR! path /opt/app-root/src/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/opt/app-root/src/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/opt/app-root/src/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /opt/app-root/src/npm-debug.log
The github repo:
https://github.com/TrueAmbition001/TrueAmbition001.github.io
Thanks in advance.
The Node.js S2I builder requires the package.json and application code to be in the root directory of the repo, you have it in a sub directory. So the structure of your code doesn't match what is required.
For some details on the S2I builder for Node.js, see:
https://github.com/sclorg/s2i-nodejs-container/tree/master/8