I'm stuck at deploying my reactJS web application to Heroku.
It worked fine on the local machine. I got problems with permission when Build section runs.
I don't know what did I wrong, everything else in this course works fine.
I tried to deploy the app with GitHub connection, but I got the same error.
I tried to run this code in terminal NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client, but I got another error (NPM... is not a command).
my package.json file :
{
"name": "contactkeeper",
"version": "1.0.0",
"description": "Contact manager app",
"main": "server.js",
"engines": {
"node": "^12.4.0"
},
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"clientinstall": "npm install --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"
},
"keywords": [],
"author": "vinogitz",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"config": "^3.1.0",
"express": "^4.17.1",
"express-validator": "^6.1.1",
"jsonwebtoken": "^8.5.1",
"lodash.template": "^4.5.0",
"mongoose": "^5.6.3"
},
"devDependencies": {
"concurrently": "^4.1.1",
"nodemon": "^1.19.1"
}
}
my gitignore like this:
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
#client/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
-----> Build
Running heroku-postbuild
> contactkeeper#1.0.0 heroku-postbuild /tmp/build_5e4bd7bd79fb3c0f84bb21cb820d7594
> NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
audited 902208 packages in 13.316s
found 0 vulnerabilities
> client#0.1.0 build /tmp/build_5e4bd7bd79fb3c0f84bb21cb820d7594/client
> react-scripts build
sh: 1: react-scripts: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! client#0.1.0 build: `react-scripts build`
npm ERR! Exit status 126
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.BWDxV/_logs/2019-07-22T11_55_03_878Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! contactkeeper#1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the contactkeeper#1.0.0 heroku-postbuild 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.BWDxV/_logs/2019-07-22T11_55_03_893Z-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
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
I found the problem. the permission denied is not the perfect error message, but i found the solution.
I tried to ignore the node_modules folder in my client folder with .gitignore, but I didn't find the solution first time, so I just delete the sub folder node_modules from project. After that, I tried to deploy it again, and it's worked. So the real problem was that, the git add, git commit, git push commands pushed the node_modules sub folder to the repository.
PS.: The solution is: write node_modules/ instead of /node_modules in gitignore. With this the node_modules folders in a project (root folder or in a sub folder get untracked.)
Thanks!
Related
I am trying to deploy my react app to the GitHub pages but I have encountered the following error:
The build folder is ready to be deployed.
To publish it at https://jatinkumarg.github.io/personal-portfolio, run:
npm run deploy
> personal-portfolio#0.1.0 deploy C:\react-projects\personal-portfolio
> gh-pages -d build
Cloning into 'node_modules\gh-pages\.cache\git#github.com!jatinkumarg!personal-portfolio.git'...
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! personal-portfolio#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the personal-portfolio#0.1.0 deploy 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\jatin\AppData\Roaming\npm-cache\_logs\2019-07-23T04_40_54_788Z-debug.log
I have already set-up and tested my ssh key, it works fine.
There is only one remote url i.e. origin(SSH)
This is my package.json
{
"name": "personal-portfolio",
"version": "0.1.0",
"homepage": "https://jatinkumarg.github.io/personal-portfolio",
"dependencies": {
"jquery": "^3.4.1",
"json-loader": "^0.5.7",
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"devDependencies": {
"gh-pages": "^1.0.0",
"react-scripts": "1.0.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
At this point, I have no idea what's wrong. Can anyone please help me with this issue?
You need the PRO plan to use GitHub pages on a private repository.
You can try adding a SSH identity in ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile /Users/myusername/.ssh/my_github_ssh_private_key_registered_on_github
it didnt help me, but here is my solution:
git remote set-url origin https://github.com/USERNAME/REPOSITORY_NAME.git
You will recieve smtn like this:
npm run deploy
> ravenous#0.1.0 predeploy C:\Users\peter\ravenous
> npm run build
> ravenous#0.1.0 build C:\Users\peter\ravenous
> react-scripts build
Creating an optimized production build...
Compiled with warnings.
./src/components/SearchBar/SearchBar.js
Line 84:21: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
./src/components/Business/Business.js
Line 9:55: Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener react/jsx-no-target-blank
Line 17:21: Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener react/jsx-no-target-blank
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
File sizes after gzip:
40.23 KB build\static\js\2.c4f174a4.chunk.js
1.76 KB build\static\js\main.f787394e.chunk.js
1.08 KB build\static\css\main.551e99bf.chunk.css
783 B build\static\js\runtime-main.647a42cc.js
The project was built assuming it is hosted at /personalportfolio/.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
To publish it at http://PetrMitin.github.io/personalportfolio , run:
npm run deploy
Find out more about deployment here:
bit.ly/CRA-deploy
> ravenous#0.1.0 deploy C:\Users\peter\ravenous
> gh-pages -d build
*** Please tell me who you are.
Run
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'peter#LAPTOP-FRARNQJG.(none)')
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ravenous#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ravenous#0.1.0 deploy 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\peter\AppData\Roaming\npm-cache\_logs\2020-01-07T23_02_19_256Z-debug.log
If you did, you are on the right way!
Then pass required info by entering in cmd or whatever:
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
And try to run:
npm run deploy
I believe that i`ve helped you to resolve your question.
I'm trying to build the nextjs, but this is with the error below. What can it be?I've run the npm run build and it still doesn't work
package.json
{
"name": "mobills-indica",
"version": "1.0.0",
"scripts": {
"install": "yarn build-all",
"next": "yarn build-firebase && cd \"src/app\" && yarn && yarn dev",
"preserve": "yarn build-all",
"serve": "firebase serve",
"predeploy": "yarn build-all",
"deploy": "firebase deploy",
"build-all": "yarn build-next && yarn build-firebase",
"build-next": "cd \"src/app\" && yarn && yarn build",
"build-firebase": "cd \"src/functions\" && yarn",
"dev": "next",
"build": "next build"
}
}
Error
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mobills-indica#1.0.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mobills-indica#1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Mobills\AppData\Roaming\npm-cache\_logs\2020-06-02T13_10_36_339Z-debug.log
I might be very late to answer this question but this is what has worked for me and it might help someone to get back on the development track!
$ npm install -g npm#latest # or, npm install -g npm#latest --prefix "C:\Program Files\nodejs"
$ rm -rf node_modules # or, `cmd /c rmdir /s /q node_modules` on Windows
$ npm install
Happy Coding!!!
I tried to run npm start to a React app that it was working perfectly, but now for some reason is not working. The mesage I recive is the following:
Error: Cannot find module 'C:\Users\albat\Desktop\personal_projects\alba_virtual_cv\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
at Function.Module._load (internal/modules/cjs/loader.js:686:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! alba_virtual_cv#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the alba_virtual_cv#1.0.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\albat\AppData\Roaming\npm-cache\_logs\2020-05-11T09_08_43_976Z-debug.log
And my package.json is the following:
{
"name": "alba_virtual_cv",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"debug": "^4.1.1"
},
"devDependencies": {},
"description": ""
}
Please I need help to run the application again.
Thank you.
Run this before starting the project:
npm -i
This installs missing packages
It just means something went wrong when dependencies were installed the first time.
I suggest doing these three steps:
npm install -g npm#latest to update npm because it is sometimes buggy.
rm -rf node_modules to remove the existing modules.
npm install to re-install the project dependencies.
This should fix the problem.
I am trying to deploy my react app to the GitHub pages but I have encountered the following error:
The build folder is ready to be deployed.
To publish it at https://jatinkumarg.github.io/personal-portfolio, run:
npm run deploy
> personal-portfolio#0.1.0 deploy C:\react-projects\personal-portfolio
> gh-pages -d build
Cloning into 'node_modules\gh-pages\.cache\git#github.com!jatinkumarg!personal-portfolio.git'...
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! personal-portfolio#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the personal-portfolio#0.1.0 deploy 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\jatin\AppData\Roaming\npm-cache\_logs\2019-07-23T04_40_54_788Z-debug.log
I have already set-up and tested my ssh key, it works fine.
There is only one remote url i.e. origin(SSH)
This is my package.json
{
"name": "personal-portfolio",
"version": "0.1.0",
"homepage": "https://jatinkumarg.github.io/personal-portfolio",
"dependencies": {
"jquery": "^3.4.1",
"json-loader": "^0.5.7",
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"devDependencies": {
"gh-pages": "^1.0.0",
"react-scripts": "1.0.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
At this point, I have no idea what's wrong. Can anyone please help me with this issue?
You need the PRO plan to use GitHub pages on a private repository.
You can try adding a SSH identity in ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile /Users/myusername/.ssh/my_github_ssh_private_key_registered_on_github
it didnt help me, but here is my solution:
git remote set-url origin https://github.com/USERNAME/REPOSITORY_NAME.git
You will recieve smtn like this:
npm run deploy
> ravenous#0.1.0 predeploy C:\Users\peter\ravenous
> npm run build
> ravenous#0.1.0 build C:\Users\peter\ravenous
> react-scripts build
Creating an optimized production build...
Compiled with warnings.
./src/components/SearchBar/SearchBar.js
Line 84:21: The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
./src/components/Business/Business.js
Line 9:55: Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener react/jsx-no-target-blank
Line 17:21: Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener react/jsx-no-target-blank
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
File sizes after gzip:
40.23 KB build\static\js\2.c4f174a4.chunk.js
1.76 KB build\static\js\main.f787394e.chunk.js
1.08 KB build\static\css\main.551e99bf.chunk.css
783 B build\static\js\runtime-main.647a42cc.js
The project was built assuming it is hosted at /personalportfolio/.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
To publish it at http://PetrMitin.github.io/personalportfolio , run:
npm run deploy
Find out more about deployment here:
bit.ly/CRA-deploy
> ravenous#0.1.0 deploy C:\Users\peter\ravenous
> gh-pages -d build
*** Please tell me who you are.
Run
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'peter#LAPTOP-FRARNQJG.(none)')
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ravenous#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ravenous#0.1.0 deploy 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\peter\AppData\Roaming\npm-cache\_logs\2020-01-07T23_02_19_256Z-debug.log
If you did, you are on the right way!
Then pass required info by entering in cmd or whatever:
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
And try to run:
npm run deploy
I believe that i`ve helped you to resolve your question.
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"
}
}