how to run multiple watch script in docker - node.js

I'am moving my react apps into docker, I am working in legacy project and we have multiple react apps. We are attaching script with react apps in script tags on every page whose need to use this files. For docker we want to use Express to serve our files.
Is there any way to run multiple watch commands ?
here is my package.json file:
{
"name": "docker apps",
"version": "3.0.0",
"description": "apps",
"license": "ISC",
"author": "devs",
"main": "main.js",
"engines": {
"node": ">=14.7.0",
"npm": ">=6.14.13"
},
"scripts": {
"requirements-check": "node checkNodeVersion.js",
"react": "webpack --env.mode production --env.app react",
"react-watch": "webpack --env.mode development --env.app react --watch",
"serve": "nodemon server.js",
"serve:prod": "node server.js --port=80",
"build": "npm run react",
"start": "npm run react-watch",
"test": "jest",
"lint": "eslint .",
"dev-start": "concurrently \"npm run react-watch\" \"npm run serve\"",
"dev-build": "concurrently \"npm run build\" \"npm run serve:prod\"",
"lint-payment": "eslint payment/",
"lint-formLibrary": "eslint formLibrary/",
"lint-fileManager": "eslint fileManager/",
"lint-blockLibrary": "eslint LPBlockLibrary/",
"lint-contracts": "eslint contracts/",
"lint-payment:fix": "eslint --fix payment/",
"lint-formLibrary:fix": "eslint --fix formLibrary/",
"lint-fileManager:fix": "eslint --fix fileManager/",
"lint-blockLibrary:fix": "eslint --fix LPBlockLibrary/",
"lint-contracts:fix": "eslint --fix contracts/",
"lint:fix": "eslint --fix ."
},
"dependencies": {
"#mikecousins/react-pdf": "^5.5.1",
"#tkaramanski/fmcomponents": "^1.6.2",
"#types/testing-library__jest-dom": "^5.9.5",
"axios": "^0.21.1",
"bootstrap": "^4.1.3",
"classnames": "^2.2.6",
"cors": "^2.8.5",
"express": "^4.17.1",
"gulp-cli": "^2.2.0",
"gulp-install": "^1.1.0",
"handlebars-loader": "^1.7.1",
"jsdom": "^16.6.0",
"lodash": "^4.17.11",
"postcss": "^8.1.4",
"postcss-js": "^3.0.1",
"prop-types": "^15.7.2",
"react": "^16.9.0",
"react-bs-notifier": "^5.0.0",
"react-datepicker": "^4.1.1",
"react-dnd": "^7.3.2",
"react-dnd-html5-backend": "^7.2.0",
"react-dom": "^16.9.0",
"react-dropzone": "^7.0.1",
"react-hook-form": "^4.9.6",
"react-hot-loader": "^4.12.18",
"react-infinite-scroll-component": "^4.2.0",
"react-jss": "^8.6.1",
"react-popper-tooltip": "^4.3.1",
"react-redux": "^7.1.3",
"react-router-dom": "^5.2.0",
"react-scrollbar": "^0.5.4",
"reactstrap": "^6.5.0",
"redux": "^4.0.4",
"redux-devtools-extension": "^2.13.8",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"reselect": "^4.0.0",
"resolve-url-loader": "^3.1.2",
"semver": "^5.7.1",
"styled-components": "^5.3.0",
"typesafe-actions": "^5.1.0"
},
"devDependencies": {
"#babel/core": "^7.13.14",
"#babel/plugin-proposal-class-properties": "^7.13.0",
"#babel/plugin-proposal-optional-chaining": "^7.13.12",
"#babel/plugin-transform-runtime": "^7.13.10",
"#babel/preset-env": "^7.13.12",
"#babel/preset-react": "^7.13.13",
"#babel/preset-stage-0": "^7.8.3",
"#babel/preset-typescript": "^7.13.0",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.5",
"#tkaramanski/fmcomponents": "^1.5.1",
"#types/jest": "^26.0.22",
"#types/react": "^17.0.3",
"#types/react-datepicker": "^4.1.4",
"#types/react-dom": "^17.0.2",
"#types/react-lazyload": "^3.1.0",
"#types/react-redux": "^7.1.16",
"#types/react-router-dom": "^5.1.8",
"#types/styled-components": "^5.1.7",
"#typescript-eslint/eslint-plugin": "^4.17.0",
"autoprefixer": "^9.8.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"babel-plugin-macros": "^3.0.1",
"babel-plugin-styled-components": "^1.12.0",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^3.0.0",
"concurrently": "^5.2.0",
"copy-webpack-plugin": "^6.0.1",
"css-loader": "^3.6.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.4",
"eslint": "^7.10.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.21.3",
"eslint-plugin-react-hooks": "^4.2.0",
"extract-loader": "^5.1.0",
"file-loader": "^6.0.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-cli": "^2.2.0",
"gulp-concat": "^2.6.1",
"gulp-sourcemaps": "^2.6.5",
"gulp-uglify": "^3.0.2",
"husky": "^4.3.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.6.3",
"mini-css-extract-plugin": "^0.9.0",
"moment": "^2.26.0",
"postcss-loader": "^3.0.0",
"prettier": "^2.4.1",
"pump": "^3.0.0",
"react-copy-to-clipboard": "^5.0.2",
"react-test-renderer": "^16.13.1",
"react-tippy": "^1.4.0",
"redux-mock-store": "^1.5.4",
"renamer": "^1.1.4",
"sass": "^1.35.1",
"sass-loader": "^8.0.2",
"style-loader": "^1.2.1",
"ts-jest": "^26.5.4",
"ts-loader": "^8.1.0",
"typescript": "4.2.3",
"url-loader": "^4.1.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-fix-style-only-entries": "^0.5.0",
"webpack-merge": "^4.2.2",
"wildcards-entry-webpack-plugin": "^2.1.0"
},
"husky": {
"hooks": {
"pre-commit": "npm run requirements-check",
"pre-push": "npm run lint"
}
},
"jest": {
"setupTestFrameworkScriptFile": "./setupTests.js",
"setupFiles": [
"./payment/src/__mocks__/data.js"
],
"collectCoverageFrom": [
"payment/src/__tests__/*.{js,jsx}",
"LPBlockLibrary/src/__testes__/*{ts,tsx}"
],
"moduleNameMapper": {
"\\.(png|jpg|gif|ttf|eot|svg)$": "<rootDir>/config/jest/fileMock.js"
},
"transform": {
"\\.tsx?$": "ts-jest",
"\\.jsx?$": "babel-jest"
}
}
}
here is my docker:
FROM node:14.17.0
WORKDIR /frontend-apps
ENV PATH /frontend-apps/node_modules/.bin:$PATH
COPY package.json \
package-lock.json \
.npmrc ./
RUN npm config set strict-ssl false
RUN npm install
RUN npm config set strict-ssl true
COPY . ./
EXPOSE 80
CMD [ "npm", "run", "dev-start"]
here is my docker-compose file.
version: '3.7'
services:
frontend-docker-app:
container_name: docker-front-apps
build:
context: .
dockerfile: Dockerfile.test
volumes:
- '.:/frontendApps'
- '/frontendApps/node_modules'
ports:
- 3000:3000
in docker file I try to run multiple commands with concurrently
"react-watch": "webpack --env.mode development --env.app react --watch",
"serve": "nodemon server.js",
"dev-start": "concurrently \"npm run react-watch\" \"npm run serve\"",

I solved my problem, it turned out that I accidentally remove my nodemon package from package.json, and I had bad docker compose config. I changed it to this version:
version: '3.7'
services:
frontend-docker-app:
container_name: docker-front-apps
working_dir: /var/www/app
build:
context: .
dockerfile: Dockerfile.test
volumes:
- .:/var/www/app
- '/frontendApps/node_modules'
tty: true
ports:
- 3000:3000
environment:
- CHOKIDAR_USEPOLLING=true
and changed cmd command from Docker file to this:
EXPOSE 80
CMD [ "npm", "run", "dev-build"]
and everything works fine.

Related

React app taking too long to start the development server

I am using a react dashboard template from themeforest. Here is the package.json content:
{
"name": "acorn-react",
"version": "1.0.1",
"private": true,
"proxy": "http://localhost:3000",
"dependencies": {
"#emoji-mart/data": "^1.0.2",
"#fullcalendar/bootstrap": "^5.9.0",
"#fullcalendar/daygrid": "^5.9.0",
"#fullcalendar/interaction": "^5.9.0",
"#fullcalendar/react": "^5.9.0",
"#fullcalendar/timegrid": "^5.9.0",
"#glidejs/glide": "^3.4.1",
"#reduxjs/toolkit": "^1.6.0",
"#testing-library/jest-dom": "^5.13.0",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^13.1.9",
"#yaireo/tagify": "^4.12.0",
"autosuggest-trie": "^2.1.1",
"axios": "^0.21.1",
"axios-mock-adapter": "^1.19.0",
"chart.js": "^3.5.1",
"chartjs-adapter-luxon": "^1.0.0",
"chartjs-plugin-crosshair": "^1.2.0",
"chartjs-plugin-datalabels": "^2.0.0",
"chartjs-plugin-streaming": "^2.0.0",
"clamp-js": "^0.7.0",
"classnames": "^2.3.1",
"date-fns": "^2.22.1",
"emoji-mart": "3.0",
"formik": "^2.2.9",
"fuse.js": "^6.4.6",
"intro.js": "^4.2.2",
"intro.js-react": "^0.5.0",
"luxon": "^2.0.1",
"overlayscrollbars": "^1.13.1",
"overlayscrollbars-react": "^0.2.3",
"pixabay-api": "^1.0.4",
"plyr-react": "^3.0.8",
"quill": "^1.3.7",
"rc-slider": "^9.7.2",
"react": "^16.13.0",
"react-autosuggest": "^10.1.0",
"react-bootstrap": "^2.0.0-rc.0",
"react-circular-progressbar": "^2.0.4",
"react-contexify": "^5.0.0",
"react-countdown": "^2.3.2",
"react-datepicker": "^4.1.1",
"react-datetime": "^3.1.1",
"react-dom": "^16.13.0",
"react-dropzone-uploader": "^2.11.0",
"react-flow-renderer": "^9.6.2",
"react-fuzzy-highlighter": "^1.0.0",
"react-helmet": "^6.1.0",
"react-hook-mousetrap": "^2.0.4",
"react-image-lightbox": "^5.1.4",
"react-intl": "^5.20.2",
"react-masonry-css": "^1.0.16",
"react-number-format": "^4.6.4",
"react-paginate": "^8.1.3",
"react-rating": "^2.0.5",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "^4.0.3",
"react-select": "^4.3.1",
"react-simple-maps": "^3.0.0",
"react-slick": "^0.29.0",
"react-sortablejs": "^6.0.0",
"react-syntax-highlighter": "^15.4.4",
"react-table": "^7.7.0",
"react-tag-autocomplete": "^6.2.0",
"react-tenor": "^2.2.0",
"react-toastify": "^7.0.4",
"react-tooltip": "^4.2.21",
"react-world-flags": "^1.5.0",
"redux-undo": "^1.0.1",
"reduxjs-toolkit-persist": "^7.0.1",
"slick-carousel": "^1.8.1",
"sortablejs": "^1.14.0",
"web-vitals": "^0.2.4",
"yup": "^0.32.9"
},
"scripts": {
"start-js": "react-scripts start --dev",
"start-css": "sass --style=compressed --watch
src/sass/styles.scss:public/css/styles.css",
"start": "concurrently \"npm run start-js\" \"npm run start-css\"",
"build-js": "react-scripts build --prod",
"build-css": "sass --style=compressed --no-source-map
src/sass/styles.scss:public/css/styles.css",
"build": "concurrently \"npm run build-css\" \"npm run build-js\"",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint ./src/**/*.js",
"lint:fix": "eslint ./src --fix",
"precommit": "lint-staged",
"concurrently": "concurrently"
},
"eslintConfig": {
"extends": [
"react-app"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --write",
"git add"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"#babel/core": "^7.18.2",
"#babel/preset-env": "^7.18.2",
"#babel/preset-react": "^7.17.12",
"babel-loader": "^8.1.0",
"babel-plugin-module-resolver": "^4.1.0",
"concurrently": "^6.2.0",
"eslint": "^7.28.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^6.0.0",
"lint-staged": "^11.0.0",
"prettier": "2.3.1",
"sass": "^1.42.1"
}
}
After I run npm start, it takes about a minute or two until I see Starting the development server and localhost starts loading in browser. And then it takes about 30 minutes until the page is loaded. (Yes 30 minutes!) . I know that the list of dependency is quite long but still I expect it to start in maximum 5 minutes. I have searched a lot for similar issues and tried to apply the suggested solutions:
Allocated more memory: --max_old_space_size=4096
Updated nodejs and npm
Closed all browser tabs before starting the app
Notes:
When I ran npm install there were dependency errors, so I had to do npm install --force
I am running this on Windows 10 , my pc has 8GB of RAM.
Thanks to everyone who will help!
I think the problem is not with the package.json. the problem is you have something that makes it slower, which is the package prettier, the same thing happened to me, the problem was the prettier package that made my app slow by taking too much time in analyzing the format and makes the format better according to the language, so this process takes times, having too much files and prettier checks all of the file again and again, the more files you have the more time it will take. So i recommend removing prettier. You can just download a vscode extension of prettier that does the job better.

Vuejs Module not found: Error: Can't resolve '../dist/helpers.esm' in node_modules/chart.js/helpers

I am trying to run npm run dev on one of my projects and getting **Module not found: Error: Can't resolve '../dist/helpers.esm' in node_modules/chart.js/helpers
You can see here => https://i.stack.imgur.com/wZc3o.png
Package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production",
"serve": "php artisan serve",
"clear-cache": "php artisan optimize:clear && composer dump-autoload && composer cc && npm cache clean --force"
},
"devDependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.0.0",
"cross-env": "^5.2.1",
"jquery": "^3.2",
"laravel-mix": "^6.0.43",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"resolve-url-loader": "^5.0.0",
"sass-loader": "^12.6.0",
"vue": "^2.5.7",
"vue-loader": "^15.9.8"
},
"dependencies": {
"chart.js": "^3.8.0",
"chartjs-plugin-datalabels": "^2.0.0",
"css-percentage-circle": "^2.0.1",
"echarts": "^5.3.2",
"jspdf": "^2.3.1",
"jspdf-autotable": "^3.5.15",
"laravel-echo": "^1.11.7",
"moment": "^2.29.1",
"moment-timezone": "^0.5.32",
"node-sass": "^7.0.1",
"npm": "^8.6.0",
"pdf-lib": "^1.17.1",
"percircle": "^1.0.28",
"percircle-vue": "^0.1.2",
"pusher-js": "^7.1.0-beta",
"tinymce": "^5.7.1",
"v-charts": "^1.17.10",
"v-skeletor": "^0.0.4",
"v-slim-dialog": "0.0.10",
"vue-axios": "^2.1.4",
"vue-chartjs": "^4.0.0",
"vue-codemirror": "^4.0.6",
"vue-confirm-dialog": "^1.0.2",
"vue-css-percentage-circle": "^2.0.0",
"vue-js-modal": "^2.0.1",
"vue-month-picker": "^1.5.0",
"vue-multiselect": "^2.1.6",
"vue-router": "^3.4.9",
"vue-step-progress": "^0.3.7",
"vue-tinymce-editor": "^1.6.2",
"vue-toast-notification": "^0.6.2",
"vue2-daterange-picker": "^0.6.8",
"vuedraggable": "^2.24.3",
"vuejs-datepicker": "^1.6.2",
"vuejs-dialog": "^1.4.2",
"vuex-persistedstate": "^3.0.0",
"yan-progress": "^1.0.3"
}
}
Node version install on my system is 18.0.0 and npm is 8.6.0
It was working just fine but now its not

Node.js Application in container starts and crashes

I have a node.js application talking to mongo database working fine locally. Mongodb is running on my lap top locally and the application is started in vscode with npm run dem. This all works fine.
The application is containerized and starts normally with same commands. However after a few seconds it crashes.
I have tried different format of docker files, docker compose, I have searched google and could not find any solution
Any help would be appreciated.
Here is my docker file
FROM node:14.15.3
ENV APP_HOME=/home/node/app
ENV NODE_ENV=production
ENV NODE_PORT=3002
RUN mkdir -pv $APP_HOME && chown -R node:node $APP_HOME
WORKDIR $APP_HOME
USER node
COPY --chown=node:node package.json $APP_HOME/
RUN npm install && npm cache clean --force
COPY --chown=node:node . .
RUN npm run build
EXPOSE $NODE_PORT
CMD ["node","./dist/server.generated.js"]
Here are the logs
docker run --name test --net app-net -p 3002:3002 test
Server started on port 3002.
Material-UI: theme.mixins.gutters() is deprecated.
/home/node/app/dist/server.generated.js:1
module.exports=function(e){var t={};function a(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}return a.m=e,a.c=t,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b69c46eb2e3b test "docker-entrypoint.s…" 16 minutes ago Exited (1) 15 minutes ago test
179c0ac2162b mongo "docker-entrypoint.s…" 10 days ago Up 10 days 0.0.0.0:27017->27017/tcp app-db
Here is the package.json
{
"name": "ecommerce",
"version": "2.0.0",
"license": "MIT",
"keywords": [
"react",
"express",
"mongodb",
"node"
],
"main": "./dist/server.generated.js",
"scripts": {
"development": "nodemon",
"build": "webpack --config webpack.config.client.production.js && webpack --mode=production --config webpack.config.server.js",
"start": "node ./node_modules/pm2/bin/pm2 start ./dist/server.generated.js --name ecommerceapp --log ../logs/app.log ",
"stop": "node ./node_modules/pm2/bin/pm2 stop ecommerceapp",
"dem": "node ./dist/server.generated.js"
},
"engines": {
"node": "14.15.3",
"npm": "8.5.5"
},
"devDependencies": {
"#babel/core": "^7.9.0",
"#babel/preset-env": "^7.9.0",
"#babel/preset-react": "^7.9.4",
"babel-loader": "^8.1.0",
"file-loader": "^6.0.0",
"nodemon": "^2.0.2",
"webpack": "^4.42.1",
"webpack-cli": "^4.3.1",
"webpack-dev-middleware": "3.7.2",
"webpack-hot-middleware": "^2.25.0",
"webpack-node-externals": "^1.7.2",
"webpack-dev-server": "^4.7.4"
},
"dependencies": {
"#babel/core": "^7.9.0",
"#babel/preset-env": "^7.9.0",
"#babel/preset-react": "^7.9.4",
"babel-loader": "^8.1.0",
"pm2": "^4.2.0",
"#hot-loader/react-dom": "^16.13.0",
"#material-ui/core": "^4.9.8",
"#material-ui/icons": "^4.9.1",
"#material-ui/styles": "^4.9.6",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-jwt": "^5.3.1",
"formidable": "^1.2.2",
"file-loader": "^6.0.0",
"helmet": "^3.22.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"mongoose": "^5.9.7",
"query-string": "^6.11.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hot-loader": "^4.12.20",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-stripe-elements": "^6.1.1",
"request": "^2.88.2",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"stripe": "^8.38.0",
"webpack": "^4.42.1",
"webpack-cli": "^4.3.1",
"webpack-dev-middleware": "3.7.2",
"webpack-hot-middleware": "^2.25.0",
"webpack-node-externals": "^1.7.2"
},
}
}

Gitlab CI/CD: Cannot find module: 'src/css/index.css'. Make sure this package is installed

I'm trying to build my React Webpack app on Gitlabs CI/CD.
Within my Webpack configuration I use the Sentry plugin to send sourcemaps so I am trying to build my app in the CI/CD container.
Here is my gitlab-ci.yml
image: node
stages:
- lint
- prepare
eslint:
stage: lint
script:
# Install eslint
- |
npm install eslint \
eslint-plugin-react \
babel-eslint
# Run eslint
- npm run lint
flow:
stage: lint
script:
# install flow
- yarn add flow-bin
- yarn run lint
sentry:
stage: prepare
script:
- npm i
environment:
name: production
only:
- master
and here is my package.json
"dependencies": {
"#babel/core": "7.1.6",
"#sentry/browser": "^4.5.1",
"#sentry/webpack-plugin": "^1.6.2",
"#svgr/webpack": "2.4.1",
"axios": "^0.18.0",
"bfj": "6.1.1",
"case-sensitive-paths-webpack-plugin": "2.1.2",
"chalk": "2.4.1",
"cors": "^2.8.5",
"cross-env": "^5.2.0",
"css-loader": "1.0.0",
"dotenv": "6.0.0",
"dotenv-expand": "4.2.0",
"express": "^4.16.4",
"express-http-proxy": "^1.5.0",
"file-loader": "2.0.0",
"fork-ts-checker-webpack-plugin-alt": "0.4.14",
"fs-extra": "7.0.0",
"html-webpack-plugin": "4.0.0-alpha.2",
"humps": "^2.0.1",
"identity-obj-proxy": "3.0.0",
"jest": "23.6.0",
"jest-pnp-resolver": "1.0.1",
"jest-resolve": "23.6.0",
"js-cookie": "^2.2.0",
"mini-css-extract-plugin": "0.4.3",
"moment": "^2.24.0",
"normalizr": "^3.3.0",
"optimize-css-assets-webpack-plugin": "5.0.1",
"pnp-webpack-plugin": "1.1.0",
"postcss-flexbugs-fixes": "4.1.0",
"postcss-loader": "3.0.0",
"postcss-preset-env": "6.3.1",
"postcss-safe-parser": "4.0.1",
"react": "^16.8.0",
"react-app-polyfill": "^0.2.0",
"react-circle": "^1.1.1",
"react-dev-utils": "^7.0.1",
"react-dom": "^16.8.0",
"react-ga": "^2.5.7",
"react-grid-system": "^4.4.1",
"react-helmet": "^5.2.0",
"react-keyboard-event-handler": "^1.4.1",
"react-media": "^1.9.2",
"react-player": "^1.8.0",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-slack-feedback": "^2.0.4",
"react-transition-group": "^2.5.3",
"redux": "^4.0.1",
"redux-api-middleware": "^3.0.1",
"redux-thunk": "^2.3.0",
"reselect": "^4.0.0",
"resolve": "1.8.1",
"sass-loader": "7.1.0",
"scrollto-with-animation": "^4.5.2",
"signale": "^1.4.0",
"striptags": "^3.1.1",
"style-loader": "0.23.0",
"styled-components": "^4.1.3",
"terser-webpack-plugin": "1.1.0",
"url-loader": "1.1.1",
"webpack": "4.19.1",
"webpack-dev-server": "3.1.14",
"webpack-manifest-plugin": "2.0.4",
"workbox-webpack-plugin": "3.6.3",
},
"scripts": {
"postinstall": "cross-env NODE_ENV=production npm run build && patch-package",
"start": "node server.js",
"dev": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js",
"storybook": "start-storybook -p 9001 -c .storybook",
"lint": "eslint ./src ./stories",
"flow": "flow ./src"
},
"devDependencies": {
"#storybook/addon-info": "^4.1.11",
"#storybook/addon-knobs": "^4.1.6",
"#storybook/addon-notes": "^4.1.6",
"#storybook/react": "^4.1.6",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
"babel-loader": "^8.0.4",
"babel-plugin-named-asset-import": "^0.3.0",
"babel-preset-react-app": "^7.0.0",
"eslint": "5.6.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-loader": "2.1.1",
"eslint-plugin-flowtype": "^3.2.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"flow-bin": "^0.90.0",
"husky": "^1.3.1",
"patch-package": "^6.0.4",
"prettier": "^1.15.3",
"prop-types": "^15.7.2",
"redux-devtools-extension": "^2.13.7"
},
It builds fine on locally but not in the CI/CD runner.
In my application I had and .env file setting the NODE_ENV
After messing around for ages I had to set the NODE_ENV when I executed npm run build
"scripts": {
"postinstall": "export NODE_ENV=production NODE_PATH=. && npm run build && patch-package"
}

heroku app crashes because of missing module, but works on localhost

I have an app that I successfully deployed to heroku, but when I try to access it, I get this screen...
The log says the following...
The error I believe is causing the issue is Error: Cannot find module 'mongoose'.
Here is my package.json for reference...
{
"name": "ovo",
"version": "1.0.0",
"description": "see and sort OVO in real time!",
"main": "server.js",
"scripts": {
"build": "webpack --config webpack.prod.config.js",
"dev": "concurrently -k \"npm run frontend\" \"npm run backend\"",
"frontend": "webpack -d --watch",
"backend": "nodemon server.js",
"start": "npm run build && NODE_ENV=production node server.js",
"test": "mocha --compilers js:babel-core/register ./test/**/*.js --require ignore-styles"
},
"engines": {
"node": "6.11.0",
"npm": "5.0.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/leojacoby/ovo.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.17.1",
"babel-core": "^6.24.1",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.0",
"enzyme": "^2.8.1",
"expect": "^1.20.2",
"express": "^4.15.2",
"immutability-helper": "^2.6.5",
"mocha": "^3.2.0",
"mongoose": "^5.4.0",
"node-sass": "^4.5.2",
"prop-types": "^15.6.0",
"rc-slider": "^8.6.0",
"rc-tooltip": "^3.7.0",
"react": "^15.5.4",
"react-addons-update": "^15.6.2",
"react-bootstrap-table": "^4.3.1",
"react-bootstrap-table-next": "^0.1.3",
"react-dom": "^15.5.4",
"react-rangeslider": "^2.2.0",
"react-redux": "^5.0.5",
"redux": "^3.7.2",
"redux-devtools": "^3.4.0",
"redux-devtools-dock-monitor": "^1.1.2",
"redux-devtools-log-monitor": "^1.3.0",
"sass-loader": "^6.0.3",
"style-loader": "^0.16.1",
"webpack": "^2.3.3"
},
"devDependencies": {
"babel-eslint": "^7.2.2",
"concurrently": "^3.5.0",
"eslint": "^3.19.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"eslint-watch": "^3.1.0",
"ignore-styles": "^5.0.1",
"nodemon": "^1.11.0",
"react-addons-test-utils": "^15.5.1",
"react-test-renderer": "^15.5.4",
"webpack-dev-middleware": "^1.10.1",
"webpack-dev-server": "^2.4.2",
"webpack-hot-middleware": "^2.18.0"
},
"bugs": {
"url": "https://github.com/leojacoby/ovo/issues"
},
"homepage": "https://github.com/leojacoby/ovo#readme",
"directories": {
"test": "test"
},
"keywords": []
}
The 'mongoose' npm package is in my package.json, and everything works just fine when I run it on my localhost. Please let me know if you want any more information and thank you for reading!
Turns out I hadn't connected my github to my heroku. I was pushing to github but it was not updating heroku so I kept experiencing the same errors. This is what I had to enable in heroku and then my edits actually manifested in the heroku.
An alternative is to just type in git push heroku master into the terminal everytime.
The last thing I had to do was type in heroku config:set MONGODB_URI='mongodb://<name>:<password>#ds123050.mlab.com:23050/ovodb' into the terminal for heroku to access my environmental variable.
Are you pushing node_modules in your code? If yes try to delete that folder and let Heroku install all modules all over again.

Resources