"eslint: Permission denied" when deploying React app on Firebase through GitLab - reactjs

I'm currently trying to setup CI through GitLab for my React app hosted on Firebase. I'm struggling to get past this point. There were some other post suggesting the use of sudo but the console told me the command was not found.
Any help would be greatly appreciated. Thanks you.
Here are my current configurations:
gitlab-ci.yml configuration file
image: node:10.15.3
cache:
paths:
- node_modules/
stages:
- build
- deploy
deploy_dev:
stage: deploy
script:
- echo "Deploying to staging environment"
- npm install -g firebase-tools
- firebase deploy --token $FIREBASE_DEPLOY_KEY --project $CI_ENVIRONMENT_NAME
environment:
name: dev
only:
- master
Package.json
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.4.1",
"firebase": "^6.6.2",
"firebase-functions": "^3.3.0",
"moment": "^2.24.0",
"node-sass": "^4.13.1",
"react": "^16.12.0",
"react-beautiful-dnd": "^11.0.5",
"react-dates": "^20.3.0",
"react-dom": "^16.12.0",
"react-moment": "^0.9.7",
"react-perfect-scrollbar": "^1.5.3",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0",
"reactstrap": "^8.2.0",
"recompose": "^0.30.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"
]
}
The console error indicating permission error
$ firebase deploy -m "Pipeline $CI_PIPELINE_ID, build $CI_BUILD_ID" --non-interactive --token $FIREBASE_DEPLOY_KEY --project $CI_ENVIRONMENT_NAME
⚠ functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions#latest in your functions directory.
=== Deploying to 'cmd-dev-bbdc4'...
i deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /builds/cmdc/cmd/functions
> eslint .
sh: 1: eslint: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! functions# lint: `eslint .`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-03T01_51_09_788Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code126
ERROR: Job failed: exit code 1

So through some experimentation I was able to determine that I had to cd into the 'functions' directory and also run NPM install. I guess this was a due to a fundamental misunderstanding of how Firebase projects are structured and of node packages.
I would love to learn more so if anyone share some reading about this, it would be appreciated.
Ended up with a script that look like the following.
deploy_dev:
stage: deploy
script:
- echo "Deploying to staging environment"
- npm install -g firebase-tools #--allow-root
- npm ci #--allow-root
- cd functions # required or would throw the "eslint: not found" error
- npm ci
- cd ..
- firebase use --token $FIREBASE_DEPLOY_KEY $CI_ENVIRONMENT_NAME
- firebase deploy -m "Pipeline $CI_PIPELINE_ID, build $CI_BUILD_ID" --non-interactive --token $FIREBASE_DEPLOY_KEY
environment:
name: dev

Related

Publish React app to Github Pages using github Actions

I made a simple Reactjs app and now I want to publish it on gh-pages.
I followed this Facebook tutorial for deploying it and it is also getting deployed from my PC. But now instead of every time manually deploying it, I thought of using Github Actions to deploy on every push to the master branch. so I wrote the below Action.
name: gh pages publish
on:
push:
branches: master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- name: publish package
run: |
yarn
npm run deploy
But this action fails because it requires the user to input the username and password.
> gh-pages -d build
fatal: could not read Username for 'https://github.com': No such device or address
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! timetablemanager#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the timetablemanager#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! /home/runner/.npm/_logs/2020-06-21T07_07_19_700Z-debug.log
##[error]Process completed with exit code 1.
How can I fix this?
Edit:
Here is the package.json file
{
"homepage": "http://itissandeep98.github.io/TimeTableManager/",
"name": "timetablemanager",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.3.2",
"#testing-library/user-event": "^7.1.2",
"bootstrap": "^4.5.0",
"bootstrap-social": "^5.1.1",
"font-awesome": "^4.7.0",
"gh-pages": "^3.1.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"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"
]
}
}
According to the create react app github pages troubleshoot here, you need to do the following.
Create a new Personal Access Token
git remote set-url origin https://<user>:<token>#github.com/<user>/<repo>.
Try npm run deploy again
Also make sure everything in your package.json is correct, but this definitely looks like an authentication issue.
Putting this here for those looking to do the same as the OG:
I created and added a personal token, and also faced some more issues.
Here are the changes I ended up making on the action file:
- name: setup git authentication
run: |
git config --global user.email "<me>#<gmail>.com"
git config --global user.name "<my_name>"
git remote set-url origin https://<user>:<token>#github.com/<user>/<repo>
- name: publish
run: |
yarn
npm run deploy
for anyone else who ends up here, you can use the secrets.GITHUB_TOKEN that is available on every action, without setting it directly in the settings for your repo.
use Joey Baruch's answer above, just replace <token> with:
${{ secrets.GITHUB_TOKEN }}
P.s. stackoverflow wont let me comment yet so I had to post this as a separate answer.

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!

Deploy react application in Git pages using Azure DevOps

I'm trying to deploy my react application (Just a very basic app) in git pages using Azure DevOps. This is to get my hands wet with Azure Devops.
First of all I configured my packag.json as below.
{
"name": "gitpages",
"version": "0.1.0",
"homepage": "https://senal.github.io/gitpage-react",
"private": true,
"dependencies": {
"gh-pages": "^2.0.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"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"
]
}
}
Please pay attention to "homepage" and "deploy" script.
In my Azure DevOps, I have modify the yml file as below.
# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
git config --global user.email "xxxx.yyyy#mymail.com"
git config --global user.name "RSF"
npm install
npm run build
npm run deploy
displayName: 'npm install and build then deploy'
However, when I run the build in DevOps I get the following error:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gitpages#0.1.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gitpages#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! /home/vsts/.npm/_logs/2019-06-13T12_03_34_094Z-debug.log
##[error]Bash exited with code '1'.
Please advice what't with my steps/scripts.
Feel free to contact me should you require more info.
UPDATE: I was able to create the page by running
npm run deploy
from my terminal.
What I would like to know is, why we can't do the same thing in DevOps?
Cheers,
RSF
I had the same issue and fixed it by supplying the Github token in the --repo option. Replace npm run deploy with,
npx gh-pages --repo https://$(GITHUB_TOKEN)#github.com/org/repo.git -d dist
and add your token as a pipeline secret.

Jenkins: Build create react app without Docker

I'm trying to build my react application using Jenkins.
I pull the source code from gitlab and trying to execute shell commands:
npm install && npm run build
But problem is that build executes endlessly and jenkins even crushes!
This is my package.json:
{
"name": "myapplication",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"jquery": "^3.3.1",
"react": "^16.5.2",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.5.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.0.3",
"react-trumbowyg": "^1.1.0",
"react-vk": "^3.5.0"
},
"scripts": {
"start": "PORT=80 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"
],
"proxy": "http://localhost:8080"
}
And jenkinks's workspace for this project:
Logs:
Checking out Revision 05de65c3548b48a798ebe2f58f8cf0be59416887 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 05de65c3548b48a798ebe2f58f8cf0be59416887
Commit message: "fix build"
> git rev-list --no-walk 05de65c3548b48a798ebe2f58f8cf0be59416887 # timeout=10
[static] $ /bin/sh -xe /tmp/jenkins4408353562870979305.sh
+ npm install
npm WARN ajv-keywords#3.2.0 requires a peer of ajv#^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
audited 32091 packages in 43.675s
found 8 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
+ npm run build
> myapplication#0.1.0 build /var/lib/jenkins/workspace/path/to
> react-scripts build
Creating an optimized production build...
Build timed out (after 3 minutes). Marking the build as failed.
Build was aborted
SSH: Current build result is [FAILURE], not going to run.
Finished: FAILURE
Most of tutorials I found suggest use docker and CI & DI frameworks.
How to build react application without those?
Npm version was invalid, I've updated it and everything is ok now.

"react-scripts start" error on new machine

I made a project (on macos) with "create react app" and committed on git.
Now I'm cloning the folder on Windows and I'm following usual steps:
node
npm
npm install
Anyway I'm having this issue back:
$ npm start
> name#0.1.0 start \\Mac\Home\Desktop\WindowsProgetti\WebApp
> react-scripts start
'\\Mac\Home\Desktop\WindowsProgetti\WebApp'
CMD.EXE è stato avviato utilizzando il percorso precedente come directory
corrente. I percorsi UNC non sono supportati. Per impostazione predefinita,
verrà utilizzata la directory di Windows.
internal/modules/cjs/loader.js:583
throw err;
^
Error: Cannot find module '\\Mac\Home\Desktop\WindowsProgetti\WebApp\node_modules\react-scripts\bin\react-scripts.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! name#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the matchplat#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\fabio\AppData\Roaming\npm-cache\_logs\2018-09-21T13_56_21_061Z-debug.log
(I know... something is in Italian language, most important stuff is English anyway.)
Package.json
{
"name": "name",
"version": "0.1.0",
"private": true,
"homepage": "http://localhost:3000",
"dependencies": {
"#material-ui/core": "^3.0.0",
"#material-ui/icons": "^3.0.0",
"create-react-app": "^1.5.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-intl": "^2.4.0",
"react-loadable": "^5.5.0",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Did lot of research on the web and on stack... lots of user having this issue but none of their solution worked for me.
Any suggestions?
Thanks a lot.
Solution:
Using PARALLELS... be sure that your project is not on on "shared" space between the two OS.
I've been not able to execute the project in the mac folder.
Been not able to execute on shared space
Worked on Windows Only space.
Thanks.

Resources