Craco unable to build react app when Deployed in Heroku - reactjs

Been at it for two days and stumped.. tried every solution I can find on stackoverflow.
Trying to deploy my MERN stack app with tailwind on Heroku. It seems Craco/tailwind is giving me problem.
Any help please?
"(node:2326) UnhandledPromiseRejectionWarning: Error: Cannot find module 'tailwindcss'
Require stack:
/tmp/build_1f05e363/frontend/craco.config.js
/tmp/build_1f05e363/frontend/node_modules/#craco/craco/lib/config.js
/tmp/build_1f05e363/frontend/node_modules/#craco/craco/scripts/build.js
"
Error build log posted below
`
-----> Building on the Heroku-20 stack
-----> Using buildpack: mars/create-react-app
-----> React.js (create-react-app) multi app detected
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
=====> Detected Framework: Multipack
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 14.17.5
engines.npm (package.json): unspecified (use default)
Resolving node version 14.17.5...
Downloading and installing node 14.17.5...
Using default npm version: 6.14.14
-----> Restoring cache
Cached directories were not restored due to a change in version of node, npm, yarn or stack
Module installation may take longer for this build
-----> Installing dependencies
Installing node modules
> nodemon#2.0.12 postinstall /tmp/build_1f05e363/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate
added 269 packages in 8.641s
-----> Build
Running heroku-postbuild
> react-ecommerce#1.0.0 heroku-postbuild /tmp/build_1f05e363
> NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend
> core-js#2.6.12 postinstall /tmp/build_1f05e363/frontend/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js#3.16.3 postinstall /tmp/build_1f05e363/frontend/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js-pure#3.16.3 postinstall /tmp/build_1f05e363/frontend/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"
> ejs#2.7.4 postinstall /tmp/build_1f05e363/frontend/node_modules/ejs
> node ./postinstall.js
added 1991 packages from 811 contributors in 51.631s
150 packages are looking for funding
run `npm fund` for details
> frontend#0.1.0 build /tmp/build_1f05e363/frontend
> craco build
`
(node:2326) UnhandledPromiseRejectionWarning: Error: Cannot find module 'tailwindcss'
Require stack:
- /tmp/build_1f05e363/frontend/craco.config.js
- /tmp/build_1f05e363/frontend/node_modules/#craco/craco/lib/config.js
- /tmp/build_1f05e363/frontend/node_modules/#craco/craco/scripts/build.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/tmp/build_1f05e363/frontend/craco.config.js:6:11)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2326) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2326) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
`
-----> Caching build
- node_modules
-----> Pruning devDependencies
audited 269 packages in 2.577s
22 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
-----> Build succeeded!
=====> Downloading Buildpack: https://github.com/mars/create-react-app-inner-buildpack.git#v9.0.0
=====> Detected Framework: React.js (create-react-app)
Writing `static.json` to support create-react-app
Enabling runtime environment variables
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-static.git
=====> Detected Framework: Static HTML
-----> Installed nginx 1.19.0 to /app/bin
Using release configuration from last framework (Static HTML).
-----> Discovering process types
Procfile declares types -> web
-----> Compressing...
Done: 103.2M
-----> Launching...
Released v20
`
{
"name": "frontend",
"proxy": "http://127.0.0.1:5000",
"version": "0.1.0",
"private": true,
"dependencies": {
"#craco/craco": "^6.2.0",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^12.8.3",
"axios": "^0.21.1",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.2",
"react-paypal-button-v2": "^2.6.3",
"react-redux": "^7.2.5",
"react-router-dom": "^5.2.1",
"react-scripts": "4.0.3",
"redux": "^4.1.1",
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.3.0",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"autoprefixer": "^9.8.7",
"postcss": "^7.0.38",
"tailwindcss": "npm:#tailwindcss/postcss7-compat#^2.2.16"
}
}
I've tried uninstalling tailwind/postcss/autoprefixer and re-installing it to dependencies and in that case, the build will still not complete with a Craco build error.
I'm stumped been trying to fix this for 8 hours..
If I bash into my heroku app:
` Running bash on ⬢ appName123... up, run.4756 (Free)
~ $ dir
Procfile README.md backend frontend node_modules package-lock.json package.json
~ $ cd backend
~/backend $ dir
config controller data middleware models routes seeder.js server.js utils
~/backend $ cd ..
~ $ cd frontend
~/frontend $ dir
craco.config.js node_modules package-lock.json package.json public src tailwind.config.js
~/frontend $ exit
exit
`
No build folder.
I try to install manually:
`~/frontend $ npm run build
> frontend#0.1.0 build /app/frontend
> craco build
(node:81) UnhandledPromiseRejectionWarning: Error: Cannot find module 'tailwindcss'
Require stack:
- /app/frontend/craco.config.js
- /app/frontend/node_modules/#craco/craco/lib/config.js
- /app/frontend/node_modules/#craco/craco/scripts/build.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/app/frontend/craco.config.js:6:11)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:81) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:81) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`
Same error.. unable to build.
Tailwind however will work locally no matter if its a regular or dev dependency and craco build runs fine every time. It's just deployment in Heroku thats causing a problem.
I've specified Node version, updated my build pack to mars create-react-app.... nothing else left to try
package.json in root folder for backend server
{
"name": "react-ecommerce",
"engines": {
"node": "14.17.5"
},
"version": "1.0.0",
"description": "MERN ecommerce shop",
"main": "server.js",
"dependencies": {
"bcryptjs": "^2.4.3",
"concurrently": "^6.2.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-async-handler": "^1.1.4",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.0.4",
"nodemon": "^2.0.12"
},
"devDependencies": {},
"scripts": {
"server": "nodemon backend/server",
"client": "npm start --prefix frontend",
"start": "node backend/server",
"dev": "concurrently \"npm run server \" \"npm run client \"",
"data:import": "node backend/seeder",
"data:delete": "node backend/seeder -d",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"
}
}
Once again, everything works locally. Even when booting up in production mode without craco run. So path seems to be fine. It's the build in Heroku will fail
Any help?

Try moving the 'tailwindcss' module to the dependencies instead to the dev dependencies.

Yep, had the same issue on my VPS, resolved it by deleting them and installing again:
npm uninstall tailwindcss postcss autoprefixer
npm install tailwindcss#npm:#tailwindcss/postcss7-compat postcss#^7 autoprefixer#^9

Related

Heroku push failing with Create-React-App

I'm trying to deploy my create-react-app using Heroku. When I do git push heroku master, the build fails.
This is the error log:
-----> React.js (create-react-app) multi app detected
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
=====> Detected Framework: Multipack
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 12.x...
Downloading and installing node 12.16.3...
Using default npm version: 6.14.4
-----> Installing dependencies
Installing node modules (package.json + package-lock)
> nodemailer#6.4.6 postinstall /tmp/build_258ba2b79ac9e7091bc7dd79a031dd4f/node_modules/nodemailer
> node -e "try{require('./postinstall')}catch(e){}"
=== Nodemailer 6.4.6 ===
Thank you for using Nodemailer for your email sending needs! While Nodemailer
itself is mostly meant to be a SMTP client there are other related projects in
the Nodemailer project as well.
For example:
> IMAP API ( https://imapapi.com ) is a server application to easily access
IMAP accounts via REST API
> NodemailerApp ( https://nodemailer.com/app/ ) is a cross platform GUI app to
debug emails
> styled-components#4.2.0 postinstall /tmp/build_258ba2b79ac9e7091bc7dd79a031dd4f/node_modules/styled-components
> node ./scripts/postinstall.js || exit 0
Use styled-components at work? Consider supporting our development efforts at https://opencollective.com/styled-components
added 1914 packages from 1179 contributors and audited 2053 packages in 49.627s
1 package is looking for funding
run `npm fund` for details
found 56466 vulnerabilities (39341 low, 26 moderate, 17098 high, 1 critical)
run `npm audit fix` to fix them, or `npm audit` for details
-----> Build
Running build
> juliesong#0.1.0 build /tmp/build_258ba2b79ac9e7091bc7dd79a031dd4f
> react-scripts build
Creating an optimized production build...
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
Failed to compile.
./src/components/PageIntro.js
Cannot find module: 'axios'. Make sure this package is installed.
You can install this package by running: npm install axios.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! juliesong#0.1.0 build: `react-scripts build `
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the juliesong#0.1.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! /tmp/npmcache.6BFeR/_logs/2020-05-17T06_58_22_399Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
- A module may be missing from 'dependencies' in package.json
https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
Love,
Heroku
! Push rejected, failed to compile React.js (create-react-app) multi app.
! Push failed
Here's my package.json file, in case it helps:
{
"name": "juliesong",
"version": "0.1.0",
"private": true,
"homepage": "https://www.juliesong.me",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"nodemailer": "^6.4.6",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-preloaders": "^3.0.3",
"react-responsive": "^6.1.2",
"react-responsive-carousel": "^3.1.49",
"react-responsive-simple": "^0.1.2",
"react-router-dom": "^4.1.1",
"react-router-hash-link": "^1.2.1",
"react-scripts": "^3.0.0",
"styled-components": "^4.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build ",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public",
"predeploy": "npm run build && cp build/index.html build/404.html",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"#babel/core": "^7.4.3",
"#storybook/addon-actions": "^5.0.6",
"#storybook/addon-links": "^5.0.6",
"#storybook/addons": "^5.0.6",
"#storybook/react": "^5.0.6",
"babel-loader": "^8.0.5",
"gh-pages": "^2.2.0"
},
"description": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/jiyoonee/Website-Portfolio.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/jiyoonee/Website-Portfolio/issues"
}
}
I did try to work around with gh-pages but it didn't seem to work so I tried switching to Heroku. It's my first time using it so any help on this issue would be appreciated. Thanks!

Developing webapp with React & Gatsby: receiving "ERROR #98123 WEBPACK Generating SSR bundle failed Cannot find module '#babel/core'"

Here is the full project on Github
I run gatsby develop and here is the full console output
gatsby develop
success open and validate gatsby-configs - 0.042s
success load plugins - 0.462s
success onPreInit - 0.012s
success initialize cache - 0.045s
success copy gatsby files - 0.240s
success onPreBootstrap - 0.062s
success createSchemaCustomization - 0.018s
success source and transform nodes - 0.165s
success building schema - 0.502s
success createPages - 0.066s
success createPagesStatefully - 0.334s
success onPreExtractQueries - 0.004s
success update schema - 0.069s
success extract queries from components - 0.204s
success write out requires - 0.043s
success write out redirect data - 0.012s
success onPostBootstrap - 0.011s
⠀
info bootstrap finished - 10.645 s
⠀
success run queries - 0.047s - 3/3 63.54/s
ERROR #98123 WEBPACK
Generating SSR bundle failed
Cannot find module '#babel/core'
Require stack:
- /Dir/node_modules/#babel/plugin-transform-react-jsx/lib/transform-classic.js
- /Dir/node_modules/#babel/plugin-transform-react-jsx/lib/index.js
- /Dir/node_modules/#emotion/babel-preset-css-prop/dist/babel-preset-css-prop.cjs.dev.js
- /Dir/node_modules/#emotion/babel-preset-css-prop/dist/babel-preset-css-prop.cjs.js
- /Dir/tutorial-part-four/node_modules/#babel/core/lib/config/files/plugins.js
- /Dir/tutorial-part-four/node_modules/#babel/core/lib/config/files/index.js
- /Dir/tutorial-part-four/node_modules/#babel/core/lib/index.js
- /Dir/tutorial-part-four/node_modules/babel-loader/lib/index.js
- /Dir/tutorial-part-four/node_modules/gatsby/dist/utils/babel-loader.js
- /Dir/tutorial-part-four/node_modules/loader-runner/lib/loadLoader.js
- /Dir/tutorial-part-four/node_modules/loader-runner/lib/LoaderRunner.js
- /Dir/tutorial-part-four/node_modules/webpack/lib/NormalModule.js
- /Dir/tutorial-part-four/node_modules/webpack/lib/NormalModuleFactory.js
- /Dir/tutorial-part-four/node_modules/webpack/lib/Compiler.js
- /Dir/tutorial-part-four/node_modules/webpack/lib/webpack.js
- /Dir/tutorial-part-four/node_modules/gatsby/dist/commands/develop.js
- ~/.config/yarn/global/node_modules/gatsby-cli/lib/create-cli.js
- ~/.config/yarn/global/node_modules/gatsby-cli/lib/index.js
File: .cache/develop-static-entry.js
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
3 pages Failed gatsby-starter-hello-world
Failed attempts so far
I've tried deleting .cache, node_modules yarn.lock/package-lock.json and reinstalling. I tried this using both npm and yarn (separately, never together), and upgrading yarn, and node
I also tried
rm ~/Library/Yarn/Caches/
yarn add #babel/core
and receive
yarn add #babel/core
yarn add v1.22.4
warning ../package.json: No license field
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
warning Pattern ["#babel/core#^7.9.0"] is trying to unpack in the same destination "~/Library/Caches/Yarn/v6/npm-#babel-core-7.9.0-ac977b538b77e132ff706f3b8a4dbad09c03c56e-integrity/node_modules/#babel/core" as pattern ["#babel/core#^7.8.7"]. This could result in non-deterministic behavior, skipping.
warning url-loader#1.1.2: Invalid bin field for "url-loader".
[3/4] 🔗 Linking dependencies...
[4/4] 🔨 Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ #babel/core#7.9.0
info All dependencies
└─ #babel/core#7.9.0
✨ Done in 164.67s.
Yarn and Gatsby version
yarn --version
1.22.4
node --version
v13.13.0
gatsby --version
Gatsby CLI version: 2.11.7
Gatsby version: 2.20.20
Note: this is the Gatsby version for the site at: /Dir/tutorial-part-four
package.json
{
"name": "gatsby-starter-hello-world",
"private": true,
"description": "A simplified bare-bones starter for Gatsby",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
},
"dependencies": {
"#babel/core": "^7.9.0",
"#types/react": "^16.0.0",
"core-js": "3",
"gatsby": "^2.20.12",
"gatsby-source-filesystem": "^2.2.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"typescript": "^3.9.0-dev.20200414"
},
"devDependencies": {
"prettier": "^1.19.1"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}

Why i am getting this error in Command Line every time i create a react app and run with "npm start"?

From some time i am always getting an error in Command Line related to my react-scripts when i run my react app using the command "npm start".I tried many solutions but nothing seem to work(like deleting node_module and reinstalling and also changing my "react-scripts" version in package.json file.The error is:
E:\MYPROJECT\react-chat-app>npm start
> react-app#0.1.0 start E:\MYPROJECT\react-chat-app
> react-scripts start
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module './util/escape'
at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (E:\MYPROJECT\react-chat-app\node_modules\cross-
spawn\lib\parse.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js
(internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-app#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\Acer\AppData\Roaming\npm-cache\_logs\2019-07-
07T13_59_34_897Z-debug.log
And here is my package.json file
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#pusher/chatkit": "^0.7.12",
"bootstrap": "^4.1.1",
"chatkit": "0.0.1-security",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"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": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Before this i wasn't having any such errors and my app used to run without such problems.But now even my already created app show this error when i run it.
I don't see in your package.json module util. Try install it npm i util

Error: Failed to load plugin import: Cannot find module 'eslint-plugin-import' when deploying a create-react-app

I'm new to create-react-app. I just made a quick setup with redux and react-router-dom which builds nicely on my computer using yarn build, but when pushing to Scalingo or Heroku the build fails with the following error:
./src/index.jsx
Error: Failed to load plugin import: Cannot find module 'eslint-plugin-import'
Referenced from:
at Array.forEach (<anonymous>)
at Array.reduceRight (<anonymous>)
I did not do anything to customize deployment, just pushed to production.
Here is the full deployment log :
Enumerating objects: 74, done.
Counting objects: 100% (74/74), done.
Delta compression using up to 4 threads
Compressing objects: 100% (68/68), done.
Writing objects: 100% (74/74), 185.95 KiB | 4.77 MiB/s, done.
Total 74 (delta 20), reused 15 (delta 0)
<-- Start deployment of xxx-app-staging -->
Fetching source code
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
engines.yarn (package.json): unspecified (use default)
Resolving node version 8.x...
Downloading and installing node 8.15.0...
Using default npm version: 6.4.1
Resolving yarn version 1.x...
Downloading and installing yarn (1.14.0)...
Installed yarn 1.14.0
-----> Restoring cache
Skipping cache restore (not-found)
-----> Building dependencies
Installing node modules (yarn.lock)
yarn install v1.14.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.2.4: The platform "linux" is incompatible with this module.
info "fsevents#1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents#1.2.7: The platform "linux" is incompatible with this module.
info "fsevents#1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > eslint-plugin-react#7.12.4" has unmet peer dependency "eslint#^3.0.0 || ^4.0.0 || ^5.0.0".
warning "react-scripts > pnp-webpack-plugin > ts-pnp#1.0.0" has unmet peer dependency "typescript#*".
warning " > eslint-config-airbnb#17.1.0" has unmet peer dependency "eslint#^4.19.1 || ^5.3.0".
warning "eslint-config-airbnb > eslint-config-airbnb-base#13.1.0" has unmet peer dependency "eslint#^4.19.1 || ^5.3.0".
warning " > eslint-plugin-import#2.16.0" has unmet peer dependency "eslint#2.x - 5.x".
warning " > eslint-plugin-jsx-a11y#6.2.1" has unmet peer dependency "eslint#^3 || ^4 || ^5".
[4/4] Building fresh packages...
Done in 12.22s.
Running build (yarn)
yarn run v1.14.0
$ react-scripts build
Creating an optimized production build...
Failed to compile.
./src/index.jsx
Error: Failed to load plugin import: Cannot find module 'eslint-plugin-import'
Referenced from:
at Array.forEach (<anonymous>)
at Array.reduceRight (<anonymous>)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
-----> Build failed
We're sorry this build is failing!
Some possible problems:
- A module may be missing from 'dependencies' in package.json
http://doc.scalingo.com/languages/javascript/nodejs#ensure-youre-tracking-all-your-dependencies
- This module may be specified in 'devDependencies' instead of 'dependencies'
http://doc.scalingo.com/languages/javascript/nodejs#install-devdependencies
Keep coding,
Scalingo
! An error occured during buildpack compilation
! Error deploying the application
! → Invalid return code from buildpack
And here is my package.json:
{
"name": "xxxx",
"version": "0.1.0",
"private": true,
"dependencies": {
"#sentry/browser": "^4.5.4",
"prop-types": "^15.7.1",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-redux": "^6.0.0",
"react-redux-i18n": "^1.9.3",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.5",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-promise": "^0.6.0",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4"
}
}
I can't understand why would I have any usage of eslint and its plugins in my production code, and how to fix this. Can you help?
The problem was adding devDependencies which are not installed in production. Overriding eslint config is ok but all needed packages has to be added to the main dependencies.
Removing this line from package.json worked for me:
"eslintConfig": {
"extends": "react-app"
}
I have prettier set up on my visual studio code. I think the issue arises because of the eslint config conflicts with prettier. There's also another option which I have not tried which is installing eslint-config-prettier. Here are the documentation on it: Integration Prettier with linters
Move all your Devdependencies to dependencies and delete the Devdependencies
Solved the problem for me
For some reason removing this from my CRA package.json worked for me in VS Code:
"babel": {
"presets": [
"react-app"
]
}
Step 3 from this tutorial worked for me:
https://medium.com/jeremy-gottfrieds-tech-blog/tutorial-how-to-deploy-a-production-react-app-to-heroku-c4831dfcfa08
Creating an Express JS server in the root folder to serve the production build
//server.js
const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port);
Installing dependencies:
npm install express express-favicon path
Then changing the "start" script in package.json to
"start": "node server.js"

Module not Found on Heroku Deploy but Found on Local

So I tried to deploy my app to Heroku and find this error Module not found: Error: Can't resolve './components/add-credentials/AddEducation' in '/tmp/build_6b46c3e828c5afc20e70a4b1b2232f69/client/src'
Everything works fine including that module in localhost. What should I change for this to work?
Complete Build Log
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): 8.11.x
engines.npm (package.json): 5.6.x
engines.yarn (package.json): 1.9.x
Resolving node version 8.11.x...
Downloading and installing node 8.11.4...
Bootstrapping npm 5.6.x (replacing 5.6.0)...
npm 5.6.x installed
Resolving yarn version 1.9.x...
Downloading and installing yarn (1.9.4)...
Installed yarn 1.9.4
-----> Building dependencies
Installing node modules (yarn.lock)
yarn install v1.9.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.2.4: The platform "linux" is incompatible with this module.
info "fsevents#1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 13.99s.
Running heroku-postbuild (yarn)
yarn run v1.9.4
$ NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
> uglifyjs-webpack-plugin#0.4.6 postinstall /tmp/build_6b46c3e828c5afc20e70a4b1b2232f69/client/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
added 1546 packages in 41.748s
> client#0.1.0 build /tmp/build_6b46c3e828c5afc20e70a4b1b2232f69/client
> react-scripts build
Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve './components/add-credentials/AddEducation' in '/tmp/build_6b46c3e828c5afc20e70a4b1b2232f69/client/src'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client#0.1.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! /tmp/npmcache.te6Qt/_logs/2018-09-14T23_46_37_674Z-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
Package.json
{
"name": "devconnector",
"version": "1.0.0",
"description": "Social network for developers",
"engines": {
"node": "8.11.x",
"npm": "5.6.x",
"yarn": "1.9.x"
},
"main": "server.js",
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "Dian Yuanda",
"license": "MIT",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"concurrently": "^4.0.1",
"create-react-app": "^1.5.2",
"express": "^4.16.3",
"global": "^4.3.2",
"gravatar": "^1.6.0",
"jsonwebtoken": "^8.2.0",
"mongoose": "^5.0.12",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"validator": "^9.4.1"
},
"devDependencies": {
"nodemon": "^1.17.5"
}
}

Resources