I am building out a ReactJS/Node.JS application in Docker. I am getting the following error where my package.json is never found:
server_1 |
server_1 | > stocklookback#1.0.0 dev /code/app/server
server_1 | > concurrently "npm run server" "npm run client"
server_1 |
server_1 | [1]
server_1 | [1] > stocklookback#1.0.0 client /code/app/server
server_1 | [1] > npm start
server_1 | [1]
server_1 | [0]
server_1 | [0] > stocklookback#1.0.0 server /code/app/server
server_1 | [0] > nodemon index.js
server_1 | [0]
client_1 | npm ERR! path /code/app/client/package.json
client_1 | npm ERR! code ENOENT
client_1 | npm ERR! errno -2
client_1 | npm ERR! syscall open
client_1 | npm ERR! enoent ENOENT: no such file or directory, open '/code/app/client/package.json'
client_1 | npm ERR! enoent This is related to npm not being able to find a file.
client_1 | npm ERR! enoent
client_1 |
client_1 | npm ERR! A complete log of this run can be found in:
client_1 | npm ERR! /root/.npm/_logs/2019-08-06T13_49_58_383Z-debug.log
server_1 | [1]
server_1 | [1] > stocklookback#1.0.0 start /code/app/server
server_1 | [1] > node index.js
server_1 | [1]
server_1 | [0] [nodemon] 1.19.1
server_1 | [0] [nodemon] to restart at any time, enter `rs`
server_1 | [0] [nodemon] watching: *.*
server_1 | [0] [nodemon] starting `node index.js`
stocklookback_client_1 exited with code 254
My Dockerfile for the client is:
FROM node:12.2.0-alpine
RUN mkdir -p /code/app/client
WORKDIR /code/app/client/
COPY package.json /code/app/client/
COPY package-lock.json /code/app/client/
RUN npm install
COPY . /code/app/client/
CMD [ "npm", "start" ]
The package.json is:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
And the docker-compose.yml is
version: '3.3'
volumes:
postgres_database :
external: false
services:
##########################
# Setup node container
##########################
server:
build: ./server
expose:
- ${APP_SERVER_PORT}
environment:
API_HOST: ${API_HOST}
APP_SERVER_PORT: ${APP_SERVER_PORT}
ports:
- ${APP_SERVER_PORT}:${APP_SERVER_PORT}
volumes:
- ./server:/code/app/server/src
command: npm run dev
##########################
# Setup client container
##########################
client:
build: ./client
environment:
- REACT_APP_PORT=${REACT_APP_PORT}
expose:
- ${REACT_APP_PORT}
ports:
- ${REACT_APP_PORT}:${REACT_APP_PORT}
volumes:
- ./client/src:/code/app/client/
- ./client/public:/code/app/client/public
links:
- server
command: npm start
The file structure is like so:
Why is my package.json not being copied over?
Related
I have a few packages managed by the Yarn workspace and a cli package that helps build them.
Is there a way to run CLI projects in the same workspace from scripts in package.json of each app?
My folder structure looks like this:
.\
| package.json
| yarn.lock
|
\---packages
+---app
| | package.json
| |
| \---src
| index.js
|
\---cli
| package.json
|
\---src
index.js
Root pakcage.json:
{
"name": "yarn-ws-cli",
"version": "1.0.0",
"private": true,
"workspaces": [
"packages/*"
]
}
Contents of /packages/app1/package.json:
{
"name": "app",
"version": "1.0.0",
"main": "src/index.js",
"devDependencies": {
"cli":"1.0.0"
},
"scripts": {
"build" : "node cli" // I want to run "/packages/cli/src/index.js".
}
}
I want to be able to run "/package/cli/src/index.js" when I run "yarn build" in the app1 directory.
However, if you run "yarn build" in this state, you will get an error message that the module cannot be found.
\yarn-ws-cli\packages\app>yarn build
yarn run v1.22.15
$ node cli
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module '\yarn-ws-cli\packages\app\cli'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
error Command failed with exit code 1.
Thank you.
I have a project written in JS around month ago. Since that time I didn't touch it.Now I wanna run the project again.
But when I type in Gitbash 'npm start' it's not opening the project in a browser.
It stucks at: 'node server.js' and doesn't go further.
Yesterday I had a problem with port 3131 where the project was deployed. I got information, the port was busy. So I used the 'netstat' command in CMD (windows) to find all open ports and then used 'taskkill' to terminate listening to port 3131.
But even after killing listening to that port, effect of 'npm start' was the same as today.
And it is happening with all my previous projects now. All of them where written during my online coding course in online coding School. I have finished it around a month ago.
Can it influence somehow at the issue with port 3131? Maybe I should change the port?
Important info: the project was deployed to Heroku, but couldn't work there. But even after deploying to Heroku 'npm start' was able to run project in the browser (a month ago).
BTW, 'npm run' looks like working fine, it runs all test etc.
Here is my package.json:
{
"name": "fer-07-project",
"version": "1.0.0",
"description": "",
"main": "index.html",
"scripts": {
"lint": "eslint --fix --ext .js,.jsx .",
"init-project": "npm install && npm-run-all init:*",
"init:dirs": "mkdirp dist src/sass src/css src/vendor src/images src/js",
"init:files": "touch README.md src/index.html src/sass/style.scss src/js/script.js",
"init:gitignore": "curl https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore -o .gitignore",
"init:gitignore:custom": "echo \"dist\" >> .gitignore",
"test": "npm-run-all test:*",
"test:html": "globstar nu-html-checker dist/*.html",
"test:js": "eslint src/js/ --fix",
"test:scss": "stylelint src/sass/",
"build": "npm-run-all build:* test",
"build:clean": "mkdirp dist && rm -r dist && mkdirp dist",
"build:copy": "copyfiles -a -u 1 -e \"**/sass/**/*\" -e \"**/.gitkeep\" \"src/**/*\" dist",
"build:sass": "node-sass --output-style compact -o dist/css src/sass",
"build:autoprefixer": "globstar autoprefixer-cli \"dist/css/*.css\"",
"build-dev": "npm-run-all build-dev:sass build:autoprefixer",
"build-dev:sass": "node-sass --output-style expanded --source-map true -o dist/css src/sass",
"server": "json-server --port 3131 --no-cors --delay 250 --watch dist/db/app.json",
"watch": "npm-run-all build build-dev -p watch:* server",
"watch:browsersync": "browser-sync start --server dist --files \"dist/**/*\" --ignore \"dist/db/**/*\"",
"watch:sassprefixer": "onchange \"src/sass/**/*.scss\" -- npm run build-dev",
"watch:copy": "onchange -e \"**/sass/**/*\" -e \"**/.gitkeep\" \"src/**/*\" -- copyfiles -a -u 1 {{changed}} dist"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"flatpickr": "^4.6.9",
"json-server": "^0.16.3",
"rangeslider-pure": "^0.4.11"
},
"devDependencies": {
"autoprefixer-cli": "^1.0.0",
"browser-sync": "^2.26.3",
"copyfiles": "^2.1.0",
"eslint": "^5.14.1",
"globstar": "^1.0.0",
"mkdirp": "^0.5.1",
"node-sass": "^4.11.0",
"npm-run-all": "^4.1.5",
"nu-html-checker": "^0.1.0",
"onchange": "^5.2.0",
"stylelint": "^9.10.1",
"stylelint-scss": "^3.5.4"
}
}
AND server.js:
/* global require, process */
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('dist/db/app.json');
const middlewares = jsonServer.defaults({
static: 'dist',
noCors: true
});
const port = process.env.PORT || 3131;
server.use(middlewares);
server.use(router);
server.listen(port);
HERE IS AN ISSUE IN GITBASH WHEN STARTING ANOTHER PROJECT WITH 'YARN START'
$ yarn start
yarn run v1.22.10
$ npm-run-all -p server:*
$ node server.js
$ webpack-dev-server --mode development --open --hot
events.js:292
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3131
at Server.setupListenHandle [as _listen2] (net.js:1318:16)
at listenInCluster (net.js:1366:12)
at Server.listen (net.js:1452:7)
at Function.listen (C:\Users\kpych.LENOVO-KP\OneDrive\Pulpit\Nowy folder (4)\Project-12_Travel_agency\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (C:\Users\kpych.LENOVO-KP\OneDrive\Pulpit\Nowy folder (4)\Project-12_Travel_agency\server.js:32:10)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1345:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 3131
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "server:api" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Gitbash npm start
I'm pretty new to React and JavaScript, but I've been having a seriously frustrating issue. My NPM start command doesn't seem to work when I run it. I've tried to run npm install after deleting the node_modules folder, but I haven't had any luck. If anyone has a solution I would really appreciate the help.
See the error message below.
ass1#0.1.0 start C:\Users\Chris Conrad\Documents\_GIT\Udemy\React\Section 3 Understanding Base Features & Syntax\ass1
> react-scripts start
'Syntax\ass1\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:1032
throw err;
^
Error: Cannot find module 'C:\Users\Chris Conrad\Documents\_GIT\Udemy\React\react-scripts\bin\react-scripts.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
at Function.Module._load (internal/modules/cjs/loader.js:898:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ass1#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ass1#0.1.0 start 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! C:\Users\Chris Conrad\AppData\Roaming\npm-cache\_logs\2020-05-21T00_32_03_270Z-debug.log
PS C:\Users\Chris Conrad\Documents\_GIT\Udemy\React\Section 3 Understanding Base Features & Syntax\ass1>
Below is my package.json
{
"name": "ass1",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I'm having issues creating my first docker container. I keep getting an error saying Cannot find module '/src/bin/www' when I enter docker-compose up In the package.json file I tried "start": "node /bin/www" and "start": "node ./bin/www" but same issue. Also the first time I ran it, it took about a minute, but ever since that when I run it, it throws the error within seconds. Don't know if that's relevant.
> backend#1.0.0 start /src
node_1 | > node ./bin/www
node_1 |
node_1 | internal/modules/cjs/loader.js:983
node_1 | throw err;
node_1 | ^
node_1 |
node_1 | Error: Cannot find module '/src/bin/www'
node_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
node_1 | at Function.Module._load (internal/modules/cjs/loader.js:862:27)
node_1 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
node_1 | at internal/main/run_main_module.js:17:47 {
node_1 | code: 'MODULE_NOT_FOUND',
node_1 | requireStack: []
node_1 | }
node_1 | npm ERR! code ELIFECYCLE
node_1 | npm ERR! errno 1
node_1 | npm ERR! backend#1.0.0 start: `node ./bin/www`
node_1 | npm ERR! Exit status 1
node_1 | npm ERR!
node_1 | npm ERR! Failed at the backend#1.0.0 start script.
node_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
node_1 |
node_1 | npm ERR! A complete log of this run can be found in:
node_1 | npm ERR! /root/.npm/_logs/2020-02-06T16_09_20_442Z-debug.log
myapp-docker_node_1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)
package.json
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node /bin/www"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.612.0",
"bcrypt": "^3.0.8",
"body-parser": "^1.19.0",
"create-hash": "^1.2.0",
"crypto": "^1.0.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.8.11",
"mongoose-unique-validator": "^2.0.3",
"multer": "^1.4.2",
"multer-s3": "^2.9.0"
}
}
docker-compose.yml
version: '3'
services:
web:
build: ./frontend
ports:
- "80:80"
links:
- node
volumes:
- "/Users/Phil/Documents/mysite/mysite-docker/frontend/dist:/usr/share/nginx/html"
node:
build: ./backend
ports:
- "3000:3000"
frontend docker file
FROM nginx
MAINTAINER Phil
VOLUME /Users/Phil/Documents/mysite/mysite-docker/frontend/dist:usr/share/nginx/html
EXPOSE 80
backend docker file
FROM node
MAINTAINER Phil
WORKDIR /src
COPY . /src
RUN npm install
RUN npm install -g nodemon
EXPOSE 3000
CMD ["npm", "start"]
When I start a dockerized Node.js testapp with
sudo docker-compose up
I get the following error:
Starting testapp_web_1 ... done
Attaching to testapp_web_1
web_1 |
web_1 | > testapp#0.0.1 start /usr/app
web_1 | > node index.js
web_1 |
web_1 | internal/modules/cjs/loader.js:613
web_1 | throw err;
web_1 | ^
web_1 |
web_1 | Error: Cannot find module 'mongodb'
web_1 | Require stack:
web_1 | - /usr/app/index.js
web_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
web_1 | at Function.Module._load (internal/modules/cjs/loader.js:526:27)
web_1 | at Module.require (internal/modules/cjs/loader.js:666:19)
web_1 | at require (internal/modules/cjs/helpers.js:16:16)
web_1 | at Object.<anonymous> (/usr/app/index.js:4:21)
web_1 | at Module._compile (internal/modules/cjs/loader.js:759:30)
web_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
web_1 | at Module.load (internal/modules/cjs/loader.js:628:32)
web_1 | at Function.Module._load (internal/modules/cjs/loader.js:555:12)
web_1 | at Function.Module.runMain (internal/modules/cjs/loader.js:826:10)
web_1 | npm ERR! code ELIFECYCLE
web_1 | npm ERR! errno 1
web_1 | npm ERR! testapp#0.0.1 start: `node index.js`
web_1 | npm ERR! Exit status 1
web_1 | npm ERR!
web_1 | npm ERR! Failed at the testapp#0.0.1 start script.
web_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
web_1 |
web_1 | npm ERR! A complete log of this run can be found in:
web_1 | npm ERR! /root/.npm/_logs/2019-05-04T15_34_04_615Z-debug.log
testapp_web_1 exited with code 1
The project structur is as follows
- testapp
--- docker-compose.yml
--- dockerfile
--- src
----- index.js
----- package.json
index.js
'use strict';
const MongoClient = require('mongodb').MongoClient;
const express = require('express');
// Constants
const PORT = 8080;
// App
const app = express();
app.get('/', (req, res) => {
res.send('Hello world\n');
});
app.listen(PORT);
console.log(`Running on Port:${PORT}`);
package.json
{
"name": "testapp",
"version": "0.0.1",
"description": "Testapp",
"author": "hi there",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.16.4",
"mongodb": "^3.2.3"
}
}
dockerfile
FROM node:12-alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
docker-compose.yml
version: '3'
services:
web:
build: .
command: npm start
volumes:
- ./src:/usr/app/
- /usr/app/node_modules
ports:
- 80:8080
I have alread read this stackoverflow thread but I couldn't solve this issue. I'm getting this error no matter what module I'm trying to use: mongodb, spdy, etc. Locally without docker the testapp is working. But I don't know what I'm doing wrong with docker. Can anyone help me?
Have volume folder mapping for node_modules and ensure it has mongo folder copied / created
version: '3'
services:
web:
build: .
command: npm start
volumes:
- ./src:/usr/app/
- ./src/node_modules:/usr/app/node_modules
ports:
- 80:8080
Ref:https://morioh.com/p/42531a398049/containerizing-a-node-js-application-for-development-with-docker-compose
You need to drop & rebuild the anonymous volume holding the node_modules for the updates to package.json to take effect.
docker-compose rm -v
# then:
docker-compose build
docker-compose up
You will only have to do this for changes to node_modules, since the other volume is linked to your ./src/, and will reflect changes on the host.