How to fix missing build script using cypress github actions? - reactjs

I have tried to add a github action, which is supposed to test my app using cypress.
This is what my workflowfile looks like:
name: Cypress Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./client
steps:
- name: Checkout
uses: actions/checkout#v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Setup Node
uses: actions/setup-node#v1
with:
node-version: 14
- name: Test
run: |
ls
cat package.json
- name: Cypress run
uses: cypress-io/github-action#v2.11.7
with:
build: npm run build
start: npm start
- name: Test
run: ls
The Test step contains cat package.json which shows, the package.json file, which looks like this:
{
"name": "client",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"dependencies": {
"#reduxjs/toolkit": "^1.6.1",
"axios": "^0.21.4",
"framer-motion": "^4.1.17",
"next": "11.1.2",
"phosphor-react": "^1.3.1",
"qs": "^6.10.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-leaflet": "^3.2.1",
"react-redux": "^7.2.5",
"uuid": "^8.3.2",
"cypress": "^8.6.0"
},
"devDependencies": {
"autoprefixer": "^10.3.4",
"cypress": "^8.6.0",
"eslint": "7.32.0",
"eslint-config-next": "11.1.2",
"postcss": "^8.3.6",
"tailwindcss": "^2.2.15"
}
}
As you can see there is a build script, however when the workflow runs it throws this error:
build app command "npm run build"
current working directory "/home/runner/work/mlc/mlc"
/opt/hostedtoolcache/node/14.18.0/x64/bin/npm run build
npm ERR! missing script: build
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-10-17T11_04_01_715Z-debug.log
Error: The process '/opt/hostedtoolcache/node/14.18.0/x64/bin/npm' failed with exit code 1
I have no idea why this happens, since the package.json sort of proves, that there is a build script.

You have to add: working-directory: client after with: inside Cypress run like this:
-
name: Cypress Tests
on: [push]
jobs: cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action#v2
with:
working-directory: client
build: npm run build
start: npm start

Related

React JS Scripts on package.json cannot yarn multiple script

I added on scripts on package.json:
yarn build
yarn serve
yarn start (to run yarn build and yarn serve)
But the problem is when I run yarn start, the terminal cannot run yarn serve but yarn build is successfully running:
When I run them separately, both are working:
{
"dependencies": {
"#babel/cli": "^7.17.10",
"#babel/core": "^7.18.2",
"#babel/preset-env": "^7.18.2",
"#babel/preset-react": "^7.17.12",
"lite-server": "^2.6.1"
},
"scripts": {
"build": "babel src --out-dir public -w",
"serve": "lite-server --baseDir public",
"start": "yarn build & yarn serve"
}
}
You need to add a second "&" in yarn build && yarn serve

.next folder is missing some files using Docker on CentOS in production mode

I am running a next.js project and everything is OK when I try building in production mode on my local system.
Even when I use docker on my system whose OS is ubuntu 18.04.2 building and running the project is successfully done. But when code is run on the server whose OS is CentOS 7.6.1810, some files in .next folder is missed which leads to error in running the project :(
This is my setup in package.json:
{
"name": "with-redux-wrapper",
"version": "2.0.0",
"scripts": {
"dev": "node server.js 0.0.0.0",
"build": "next build",
"start": "node server",
"export": "next export"
},
"dependencies": {
"#sentry/browser": "^5.4.3",
"#zeit/next-css": "^1.0.1",
"#zeit/next-source-maps": "0.0.4-canary.1",
"animated-scroll-to": "^1.2.2",
"isomorphic-fetch": "^2.2.1",
"isomorphic-unfetch": "^3.0.0",
"js-cookie": "^2.2.1",
"next": "8.1.0",
"next-cookies": "^1.1.3",
"next-redux-wrapper": "2.0.0",
"next-routes": "^1.0.17",
"next-seo": "^1.12.0",
"node-fetch": "^2.6.0",
"nprogress": "^0.2.0",
"react": "16.8.6",
"react-datepicker2": "^2.0.5",
"react-dom": "16.8.6",
"react-hotjar": "^2.0.0",
"react-lottie": "^1.2.3",
"react-markdown": "^4.0.8",
"react-persian-datepicker": "^3.0.2",
"react-recaptcha": "^2.3.8",
"react-redux": "5.0.7",
"react-scroll-up": "^1.3.3",
"react-slick": "^0.21.0",
"react-slick-16": "^0.16.1",
"redux": "4.0.0",
"redux-api-middleware": "^3.0.1",
"redux-devtools-extension": "2.13.2",
"redux-thunk": "2.2.0",
"slick-carousel": "^1.8.1"
},
"license": "ISC",
"devDependencies": {
"express": "^4.17.1",
"persian-date": "^1.1.0",
"serve": "^11.1.0"
}
}
And my Dockerfile which forced me to comment the commented lines because production mode causes problems:
FROM node:10.16-alpine AS build-stage
WORKDIR /app
COPY package*.json /app/
RUN npm config set unsafe-perm true
RUN npm install --verbose
# --> ENV NODE_ENV=production
COPY . /app/
RUN npm run build
# --> RUN npm run export
RUN ls .next -a
RUN npm install -g pm2
# --> CMD ["pm2-runtime", "ecosystem.config.js", "--env", "production"]
CMD ["pm2-runtime", "server.js"]
ecosystem.config.js:
module.exports = {
apps : [{
name: "app",
script: "./server.js",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}]
}
next.config.js:
const withCSS = require('#zeit/next-css')
const withSourceMaps = require('#zeit/next-source-maps')()
const webpackConfig = config => {
console.log = function() {}
return config
}
module.exports = withCSS(withSourceMaps({
webpack: webpackConfig,
}))
And the errors I got ONLY when running on ther server WITHOUT COMMENTING THE MENTIONED LINES:
ENV NODE_ENV=production; RUN npm run build:
Error: Could not find a valid build in the '/app/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (/app/node_modules/next-server/dist/server/next-server.js:271:23)
at new Server (/app/node_modules/next-server/dist/server/next-server.js:38:29)
at module.exports (/app/node_modules/next-server/index.js:4:10)
at module.exports (/app/node_modules/next/dist/server/next.js:9:12)
at Object.<anonymous> (/app/server.js:8:13)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
RUN npm run export:
{ Error: ENOENT: no such file or directory, open '/app/.next/BUILD_ID'
at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at Object.default_1 [as default] (/app/node_modules/next/dist/export/index.js:36:26)
at nextExport (/app/node_modules/next/dist/cli/next-export.js:61:21)
at commands.(anonymous function).then (/app/node_modules/next/dist/bin/next:86:36)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/app/.next/BUILD_ID' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! with-redux-wrapper#2.0.0 export: `next export`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the with-redux-wrapper#2.0.0 export 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/2019-09-03T05_11_45_045Z-debug.log
The problem was about some troubles about next.js on centos and solved by changing server Operating System to ubuntu.

I'm trying to deploy my Gatsby Blog on Github pages, but "npm run deploy" returns error

I tried to build and deploy my Gatsby blog on github pages.
I followed Gatsby's docs about deploy: https://www.gatsbyjs.org/docs/deploy-gatsby/
I run the following command:
npm run deploy
I encountered:
Cannot read property 'email' of null
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-hello-world# deploy: `gatsby build && gh-pages -b master -d public`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-starter-hello-world# 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! /Users/ChaewonKong/.npm/_logs/2018-09-20T09_34_57_114Z-debug.log
This is my gatsby-config.js looks like:
module.exports = {
siteMetadata: {
title: `Leon Kong's Blog`
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `src`,
path: `${__dirname}/src/`
}
},
`gatsby-transformer-remark`
]
};
This is my package.json:
{
"name": "gatsby-starter-hello-world",
"description": "Gatsby hello world starter",
"license": "MIT",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve",
"deploy": "gatsby build && gh-pages -b master -d public"
},
"dependencies": {
"gatsby": "^2.0.0",
"gatsby-source-filesystem": "^2.0.1",
"gatsby-transformer-remark": "^2.1.3",
"react": "^16.5.1",
"react-dom": "^16.5.1"
},
"devDependencies": {
"gh-pages": "^2.0.0"
}
}
Plus, I'm trying to make an user/organization site like:
https://username/github.io
I'm just guessing email is not set in your git config. Try to run git config user.email to see if it's there.
You can follow this article on how to add it https://help.github.com/articles/setting-your-commit-email-address-in-git/.
Also, here are docs on how to set a github page.

"Module not found" when deploying React app to Heroku

When I try to deploy my React app (made with create-react-app) to Heroku (using create-react-app-buildpack) I get the following error:
Failed to compile.
Module not found: Error: Can't resolve 'jquery' in
'/tmp/build_049d73accaf035b451adf36ac44318d3/src/components'
npm ERR! Linux 3.13.0-128-generic
npm ERR! argv
"/tmp/build_049d73accaf035b451adf36ac44318d3/.heroku/node/bin/node"
"/tmp/build_049d73accaf035b451adf36ac44318d3/.heroku/node/bin/npm" "run"
"build"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! life-quality-data#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
When testing on my computer everything works. I also have jQuery added as a dependency in package.json:
{
"name": "life-quality-data",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.16.2",
"dns": "^0.2.2",
"fetch": "^1.1.0",
"jquery": "^3.2.1",
"node-sass-chokidar": "0.0.3",
"numeral": "^2.0.6",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-router-dom": "^4.2.2",
"react-scripts": "1.0.12",
"xml2js": "^0.4.19"
},
"scripts": {
"build-css": "node-sass-chokidar src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
I think I might be missing a line. Also, could it be the .gitignore? Because on GitHub the node modules are being ignored.

React Native XcodeBuild fails on header import in CI

I am attempting to build a React Native application on an Os X CircleCI box.
My circle.yml is as follows:
machine:
xcode:
version: 8.3.3
environment:
PATH: '$PATH:$HOME/node/node-v4.4.3-darwin-x64/bin'
dependencies:
pre:
- brew install node
- npm install -g react-native-cli
- npm install
- react-native link
test:
override:
- set -o pipefail && xcodebuild -project 'ios/myApp.xcodeproj' -scheme 'myApp' clean build test -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=9.0,name=iPhone 6' CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= PROVISIONING_PROFILE= | tee $CIRCLE_ARTIFACTS/xcode_raw.log | xcpretty --color --report junit --output $CIRCLE_TEST_REPORTS/xcode/results.xml
Which fails with:
/Users/distiller/my-app/ios/myApp/AppDelegate.m:12:9: 'React/RCTBundleURLProvider.h' file not found
#import <React/RCTBundleURLProvider.h>
My package.json is follows:
{
"name": "myApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"test-watch": "jest --watch",
"test-coverage": "jest --coverage"
},
"dependencies": {
"#turf/circle": "^4.5.2",
"#turf/envelope": "^4.5.2",
"#turf/helpers": "^4.5.2",
"gl-react-native": "^2.42.3",
"react": "~15.4.0-rc.4",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.6.1",
"react-native": "0.39.2",
"react-native-config": "0.5.0",
"react-navigation": "^1.0.0-beta.11",
"react-test-renderer": "^15.6.1"
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.0.0",
"enzyme": "^2.9.1",
"enzyme-to-json": "^1.5.1",
"jest": "20.0.4"
},
"rnpm": {
"assets": [
"assets/fonts"
]
},
"jest": {
"preset": "react-native",
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"coverageDirectory": "__coverage__",
"snapshotSerializers": [
"./node_modules/enzyme-to-json/serializer"
],
"transformIgnorePatterns": [
"node_modules/(?!react-native|native-base|react-navigation|react-native-fabric)"
],
"setupFiles": [
"./test-setup.js"
]
}
}
By running a build with ssh enabled and inspecting the version, I can say that react-native-cli is installed at 2.0.1
Interestingly, this behaviour does not exhibit when the project is built (with the exact same command) on my machine (localhost)
By googling, I have found things like: React Native 0.40.0 : RCTBundleURLProvider.h” file not found - AppDelegate.m
Describing my problem exactly, however they are all limited to RN 4.0, while my package.json is explicitly pegged at 3.9.2
Any help would be greatly appreciated!
The solution seemed to be to delete my ios/build directory. Once I did so, I started having the same behavior locally as in CircleCi (which I could then fix by simply taking React out of the import path like so:
#import <RCTBundleURLProvider.h>
I had this problem because my test script wasn't running yarn install. So a fresh clone and build would fail. You could add something like this to your config.yml file:
- run:
name: Install React Native
command: yarn install

Resources