When I build my NX monorepo project with Github action workflow, I get the following error:
fatal: No such ref: <COMMIT_HASH>.
This is my build step:
build:
name: Build
needs:
- config
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Pull the full git history
uses: actions/checkout#v3
with:
fetch-depth: 0
- name: Sets the base and head SHAs
uses: nrwl/nx-set-shas#v3
- name: Restore node modules from cache
id: node-modules
uses: actions/cache#v2
with:
path: ./node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install Node.js
uses: actions/setup-node#v2
with:
node-version: '16'
check-latest: true
- run: git fetch
- name: Install node modules
if: ${{ steps.node-modules.outputs.cache-hit != 'true' }}
run: npm ci
- name: Install SAM
uses: aws-actions/setup-sam#v1
- name: Restore repository from cache
uses: actions/cache#v2
with:
path: |
./*
!./node_modules
key: ${{ github.sha }}-run-${{ needs.config.outputs.run-timestamp }}
- name: Cache the build directory
uses: actions/cache#v2
with:
path: ./.aws-sam/*
key: ${{ github.sha }}-build-${{ needs.config.outputs.run-timestamp }}
- name: Build the Lambda
shell: bash
run: npm run affected:build --args='--envType=prod'
The nrwl/nx-set-shas#v3 action injects the base and head automatically to the nx script. The build recognize and prints the base and the head SHAs:
This is my package.json script:
"scripts": {
"prepare": "cd ${pwd} && husky install ${pwd}/.husky",
"lint": "nx lint --verbose",
"affected:lint": "nx affected --target=lint --verbose",
"test": "nx test --verbose",
"affected:test": "nx affected --target=test --verbose",
"build": "nx build --verbose",
"affected:build": "nx affected --target=build --verbose",
"deploy": "nx deploy --verbose",
"affected:deploy": "nx affected --target=deploy --verbose"
}
Any ideas?
Related
I'm using WSL Ubuntu to run a react-relay project, but after installing watchman using brew and trying to run the app in watch mode, watchman gives me the following error(I have run the project using yarn start):
Watchman error: The watchman server reported an error: "watchman::QueryExecError: query failed: synchronization failed: syncToNow: timed out waiting for cookie file to be observed by watcher within 60000 milliseconds: Connection timed out", while executing command: QueryRequest(
"query",
"/mnt/d/Work/Personal/react-relay-tutorial",
QueryRequestCommon {
glob: None,
glob_noescape: false,
glob_includedotfiles: false,
path: Some(
...
I've been trying reinstalling watchman without brew, with brew, the same error I get, nothing on the internet helped...
My package.json file:
...
"scripts": {
"start": "yarn run relay && react-scripts start",
"build": "yarn run relay && react-scripts build",
"relay": "yarn run relay-compiler --watch $#",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"relay": {
"src": "./src/",
"schema": "./src/schema.graphql"
},
...
"devDependencies": {
"babel-plugin-relay": "^13.1.1",
"graphql": "^16.3.0",
"relay-compiler": "^13.1.1"
}
...
relay.config.js file
module.exports = {
// ...
// Configuration options accepted by the `relay-compiler` command-line tool and `babel-plugin-relay`.
src: './src',
schema: './src/schema.graphql',
exclude: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'],
};
.babel.rc
{
"plugins": [
"relay"
]
}
Project structure:
PS: when running the project without any watchman it works just fine
I have a series of Jenkinsfiles that looks like this (this is the production version):
pipeline {
agent {
dockerfile {
filename 'Dockerfile'
dir 'jenkins/'
label 'agent && linux'
args '''
-v /var/lib/package-cache/.npm:/.npm:rw,z
'''
}
}
environment {
NODE_ENV = "production"
}
stages {
stage('Install dependencies') {
steps {
sh "npm ci --production=false"
sh "npx cypress install"
sh "npm install -g cross-env"
}
}
stage('Cypress tests') {
parallel {
stage('Start local server') {
steps {
sh returnStatus: true, script: "npm run start:test"
}
}
stage('Run Cypress tests') {
steps {
sh 'npm run wait'
sh 'cross-env NODE_ENV=test npm run cypress:run'
sh 'killall node'
}
}
}
}
stage('Build') {
steps {
sh "npm run build:${NODE_ENV}"
}
}
stage('Deploy') {
steps {
sh "npm run publish:${NODE_ENV}"
}
}
}
post {
always {
echo "Job completed"
}
}
}
Note that the versions for the Jenkinsfile for the other environments use that particular environment (development, qa, and staging) for the NODE_ENV = "{ENV}" line.
The scripts in my package.json includes the following:
{
"start": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack-dev-server --http --port 9003",
"start:development": "cross-env NODE_ENV=development npm run start",
"start:test": "cross-env NODE_ENV=test npm run start",
"start:qa": "cross-env NODE_ENV=qa npm run start",
"start:staging": "cross-env NODE_ENV=staging npm run start",
"start:production": "cross-env NODE_ENV=production npm run start",
"cypress:run": "cypress run",
},
In all non-production environments, the npm run start:test line in the Jenkinsfile correctly uses test for NODE_ENV when webpack dev server starts. When the production Jenkinsfile is used, however, it ends up using production for NODE_ENV rather than test when npm run start:test is called.
What would be causing my npm run start:test script to be ignoring the value (of test) I'm setting via cross-env and, instead, using production?
i am trying to fetch data from the db.json.
here is my db.json file:
{
"posts": [
{ "id": "react-hooks", "title": "React Hooks", "content": "The greatest thing since sliced bread!", "author": "ali" },
{ "id": "react-fragments", "title": "Using React Fragments", "content": "Keeping the DOM tree clean!", "author": "ali" }
],
"users": [
{ "id": 1, "username": "ali", "password": "********" }
],
"themes": [
{ "id": 1, "primaryColor": "deepskyblue", "secondaryColor": "coral" },
{ "id": 2, "primaryColor": "orchid", "secondaryColor": "mediumseagreen" },
{ "id": 3, "primaryColor": "darkslategray", "secondaryColor": "slategray" }
]
}
after that i have executed > npm install --save json-server and > npx json-server --watch server/db.json and i have edited the "scripts": part as followed:
"start:server": "npx json-server --watch server/db.json",
"start:client": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
then i have excuted > npm install --save concurrently and then i have added that line in the "scripts":
"start": "npx concurrently \"npm run start:server\" \"npm run start:client\"",
then i have executed > npm install --save http-proxy-middleware and after that i have created setupProxy.js and put the following code:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports=function(app){
app.use(createProxyMiddleware('/api',{
target:'http://localhost:5000',
pathRewrite:{'^/api':''}
}))
}
then i excuted npm install and after that when i execute npm start it shows the following error:
The system cannot find the file :client.
[5] start:client exited with code 1
[2] The system cannot find the file :server.
[2] start:server exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reacttutorial#0.1.0 start: `npx concurrently "npm run start:server" "npm run start:client"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reacttutorial#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
and there are two windows alerts which are saying that ':server' and ':client' cannot be found.
i have created whole new app by executing npx create-react-app reacttutorial. i am just running out of ideas. can anyone help me on that please?
look at this reply React scripts fails while i run concurrently with nodemon
so you put in
"scripts": {
"dev": "concurrently \"npm run server\" \"npm run react\"",
"server": "npx json-server --watch server/db.json --port 4000 --routes server/routes.json",
"react": "react-scripts start",
...}
and use npm run dev instead or npm start
worked for me
and also use createProxyMiddleware instead of proxy in setupProxy.js file
So when I run locally the mocha test inside my repo It works just fine but when I push a commit and it runs on travis CI I keep getting this error:
sh: 1: mocha: Permission denied
npm ERR! Test failed. See above for more details.
my .travis.yml
language: node_js
node_js:
- "6"
install:
-npm install
before_script: npm install -g mocha
before_script: chmod 0777 ./node_modules/.bin/mocha
package.json
{
"name": "skeletonapp",
"version": "0.0.0",
"description": "skeletonapp",
"main": "index.js",
"author": {
"name": "li"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"chai": "^3.5.0",
"mocha": "^3.1.2"
}
}
structure of files
https://travis-ci.org/LiamDotPro/Travis-CI-NodeJS-Skeleton---Mocha-Chai/builds/173340318
test.js
var assert = require('assert');
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1, 2, 3].indexOf(4));
});
});
});
Turn on the execute permission on node_modules/.bin: https://github.com/travis-ci/travis-ci/issues/6828#issuecomment-258581083
Or, remove node_modules from your Git repository, and let Travis install it with npm install. (See https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Travis-CI-uses-npm.)
Do not install mocha to Travis-CI manually. It's here by default.
Just remove your before_script's statements from the .travis.yml file.
I have the latest NodeJS installed and for any JavaScript files, I can execute it with node myscript.js but recently I'm learning es6 and for some of the latest syntax, it just pop out some errors/exceptions while executing. I tried babel-cli, but didn't seem to work as it is for compile es6 to 5 not for command line execute.
1) To enable the support of ES6, use the --harmony flag:
node --harmony myscript.js
This will enable the available ES6 syntax in node. But notice it's currently a limited subset of the ES6 standard (see the compatibility table).
2) To have a complete compatibility, you have to use babel node.
Install #babel/node to get a babel-node executable which works exactly the same as Node.js's CLI, only it will compile ES6 code before running it.
babel-node myscript.js
For simple ES6 or even Typescript experimentation, maybe Deno could be considered nowadays. It supports newest ES (and TS) out of the box without needing any additional tooling.
#source1
https://dev.to/geekygeeky/get-started-with-es6-javascript-for-writing-nodejs-using-express-544h
#create dir /project1
mkdir /project1
cd /project1
#install babel etc
npm i #babel/cli #babel/core #babel/node #babel/preset-env --save-dev
npm i #babel/plugin-proposal-class-properties #babel/plugin-proposal-object-rest-spread --save-dev
npm i rimraf nodemon --save-dev
#initialize project1
#https://philna.sh/blog/2019/01/10/how-to-start-a-node-js-project/
npm init
#edit /project1/package.json
nano /project1/package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rimraf dist && babel src --out-dir dist --copy-files",
"start": "node dist/app.js",
"start:dev": "nodemon --exec babel-node src/app.js"
},
#edit /project1/.babelrc
nano /project1/.babelrc
{ "presets": [
["#babel/env", {
"targets": {
"node": "current"
}
}]
],
"plugins": [
"#babel/plugin-proposal-class-properties",
"#babel/plugin-proposal-object-rest-spread"
]
}
#install express
npm i express --save
#open a bash shell
#create /project1/src
mkdir src
cd src
#edit /project1/src/app.js
nano /project1/src/app.js
import express, { json } from 'express';
import items from './items';
const app = express();
app.use(json())
const PORT = process.env.PORT || 3000;
app.get('/', async (req, res) => {
res.json({ status: true, message: "Our node.js app works" })
});
app.get('/items', (req, res) => {
res.json({ status: true, message: "Fetched all items", data: items })
})
app.listen(PORT, () => console.log(`App listening at port ${PORT}`));
#edit /project1/src/items.js
nano items.js
const items = [
{
id: 1,
username: "John doe",
cartItems: ['football', 'ps5', 'cd-rom'],
},
{
id: 2,
username: "Jane doe",
cartItems: ['mobile phone', 'game pad'],
}
];
export default items;
#open another bash shell
#run server
cd /project1
npm run start:dev
#keep the server running
#check your app via browser
http://localhost:3000
http://localhost:3000/items