Concurrently npm with React Js - npm

I have a project which is created using Node express and React Js. The server(Node) package.json as follows. It uses concurrently to start both server and client as once using npm run dev. The server uses port 5000 and the client uses port 3000 And the Folder structure as follows.
/
|
|-mysample
|
|-client
| |-.env
| |-package.json
| |-src
|-server.js
|-package.json
package.json(mysample)
{
"name": "mysample",
"version": "1.0.0",
"description": "My Sample",
"main": "server.js",
"scripts": {
"client-install": "npm install --prefix client",
"start": "nodemon server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "test",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"concurrently": "^4.0.1",
"express": "^4.16.4",
"mongoose": "^5.3.8",
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}
How can I use concurrently npm package to start two react js projects which uses port 3000 for admin and 8000 for client.
/
|-ebook_admin
|
|-client
| |-.env
| |-package.json
| |-src
| |-public
| |
|-package.json
|-src
|-public
|-.env

If I understand your question correctly, you can take a look at one of my projects here https://github.com/chriskavanagh/mern-shopping-list/blob/master/package.json to see how as long as you've set up a proxy here https://github.com/chriskavanagh/mern-shopping-list/blob/master/client/package.json changing the port to 8000.
This is the backend package.json
"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",
"test": "echo \"Error: no test specified\" && exit 1"
},
and
"proxy": "http://localhost:8000", in your client package.json

Solution is Here, first of all install concurrently(npm).
"scripts": {
"client-install": "npm install --prefix client",
"start": "nodemon server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"cd server && npm server"\ \"npm run client"\"
Than in your CLI: npm run dev
It's work! SkraJ5

Related

npm run dev is not working missing script how do I fix this

I have downloaded a zip file of a Barba project, unzipped opened it in VS then npm install yarn and then npm run dev.. I get error missing script dev. What am I missing ?
"name": "barba-starter-template",
"version": "1.0.0",
"description": "A simple starter template for setting up a ECMAScript 6 project with barba.js and webpack.",
"main": "app.js",
"scripts": {
"dev": "webpack-dev-server --mode development",
"build": "webpack --mode production",
"start": "node index.js"
},

How to use concurrently in Yarn package?

The default package manager in my system is Yarn. I am trying to follow a course that uses NPM. Instead of shifting to NPM, I wanted to continue in Yarn but I got stuck in concurrently. How can I convert the following code for Yarn?
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "npm start --prefix frontend",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"data:import": "node backend/seeder",
"data:destroy": "node backend/seeder -d",
yarn version for above code will be:
"start": "node backend/server",
"server": "nodemon backend/server",
"client": "yarn --cwd frontend start",
"dev": "concurrently \"yarn server\" \"yarn client\"",
"data:import": "node backend/seeder",
"data:destroy": "node backend/seeder -d"
CWD - current working directory

'gatsby build' failing in Travis CI - error #98123 WEBPACK

I'm trying to deploy my portfolio website using AWS S3, CloudFront, CodePipeline, and Travis CI.
Everything works fine, but Travis CI build keeps failing.
gatsby build gives me an error with:
error #98123 WEBPACK
Generating JavaScript bundles failed
This question is very similar to mine, but the solution was irrelevant to mine because I don't have yarn file and I tried reinstalling my npm dependencies.
Here is the copy of my logs:
Generating JavaScript bundles failed
Can't resolve '../components/Layout' in '/home/travis/build/stomg7969/react-portfolio/src/pages'
File: src/pages/index.js
See our docs page for more info on this error: https://gatsby.dev/issue-how-to
error #98123 WEBPACK
Generating JavaScript bundles failed
Can't resolve '../components/Layout' in '/home/travis/build/stomg7969/react-portfolio/src/pages'
File: src/pages/404.js
See our docs page for more info on this error: https://gatsby.dev/issue-how-to
The command "gatsby clean && gatsby build" exited with 1.
store build cache
Done. Your build exited with 1.
And here is my package.json.
"name": "gatsby-starter-spectral",
"version": "0.0.1",
"description": "Gatsby.js V2 starter template based on Spectral by HTML5 UP",
"repository": {
"type": "git",
"url": "git+https://github.com/anubhavsrivastava/gatsby-starter-spectral.git"
},
"author": {
"name": "Anubhav Srivastava",
"email": "anubhav.srivastava00#gmail.com"
},
"dependencies": {
"gatsby": "^2.13.39",
"gatsby-plugin-manifest": "^2.2.3",
"gatsby-plugin-offline": "^2.1.0",
"gatsby-plugin-react-helmet": "^3.0.12",
"gatsby-plugin-sass": "^2.0.11",
"node-sass": "^4.12.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-helmet": "^5.2.1",
"react-images": "1.0.0",
"react-scrollspy": "^3.4.0",
"smoothscroll-polyfill": "^0.4.4"
},
"scripts": {
"develop": "gatsby develop",
"build": "npm run clean && gatsby build",
"deploy": "npm run clean && gatsby build --prefix-paths && gh-pages -d public",
"serve": "gatsby serve",
"clean": "rimraf .cache public",
"format": "prettier --write '**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"gh-pages": "^2.0.1",
"prettier": "^1.17.0",
"rimraf": "^2.6.3"
},
"keywords": [
"gatsby",
"gatsby-starter",
"gatsby-starter-spectral"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/anubhavsrivastava/gatsby-starter-spectral/issues"
},
"homepage": "https://github.com/anubhavsrivastava/gatsby-starter-spectral#readme"
}
Lastly, this is my .travis.yml file.
language: node_js
node_js:
- 11.8.0
install: npm install
script: gatsby clean && gatsby build
deploy:
provider: s3
access_key_id: $AWS_KEY
secret_access_key: $AWS_SECRET
bucket: 'thedevelopark.com'
skip_cleanup: true
acl: public_read
local_dir: public
Thank you in advance for your feedback.
I've had the same problem and tried and checked case-sensitivity a thousand times. Wouldn't do anything.
Then I changed the name of the component in all areas, filename, import, export, you name it. Now it works.
I don't know if Netlify had a problem with my component's name "Socials"? Guess I'll never find out.

jspm install github library

I'm tring to use https://github.com/intljusticemission/react-big-calendar after forking
I can jspm install -dev github:pcompassion/react-big-calendar fine.
But it's lacking lib directory, I think jspm is not running "scripts" in package.json (Is it supposed to do?)
"scripts": {
"clean": "rimraf lib",
"clean:examples": "rimraf examples/static",
"less": "lessc --autoprefix=\"ie >= 10, last 2 versions\" src/less/styles.less ./lib/css/react-big-calendar.css",
"assets": "cpy src/less/* lib/less",
"build": "npm run clean && babel src --out-dir lib && npm run assets && npm run less",
"build:examples": "npm run clean:examples && webpack --config webpack/examples.config.es6.js",
"build:visual-test": "webpack --config webpack/visual-test.es6.js",
"examples": "npm run clean:examples && webpack-dev-server --inline --hot --config webpack/examples.config.es6.js",
"lint": "eslint src --ext .jsx --ext .js",
"storybook": "start-storybook -p 9002",
"test": "npm run lint",
"tdd": "karma start",
"release": "release"
},
So I should go to the folder and mannualy do npm install ?

npm && not working to run two tasks

I'm trying to use straight up npm as my build tool.
{
"name": "ang-starter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"jshintConfig": {
"predef": ["angular"]
},
"scripts": {
"autoprefixer": "postcss -u autoprefixer -r src/assets/css/*",
"scss": "node-sass --output-style compressed -o src/assets/css src/assets/sass/main.scss",
"jshint": "jshint src/app/*.js",
"uglify": "uglifyjs src/app/*.js -o src/assets/js/app.min.js",
"serve": "browser-sync start --server --files 'src/assets/css/, src/assets/js/*.js, **/*.html, !node_modules/**/*.html'",
"watch:css": "onchange 'src/assets/sass/*.scss' -- npm run scss",
"watch:js": "onchange 'src/app/**/*.js' -- npm run jshint && npm run uglify",
"watch:all": "npm-run-all -p serve watch:css watch:js watch:images",
"postinstall": "npm run build:all && npm run watch:all"
},
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^6.3.7",
"browser-sync": "^2.13.0",
"jshint": "^2.9.2",
"node-sass": "^3.8.0",
"npm-run-all": "^2.3.0",
"onchange": "^2.5.0",
"postcss-cli": "^2.5.2",
"uglify-js": "^2.6.4"
}
}
My folder set up is like.
src
app
controllers
directives
filters
services
assets
css
images
js
sass
templates
index.html
package.json
My problem is with watch:js, I can run jshint and uglify separately and they work but if I run watch:js which uses && to run jshint and then uglify then the uglify doesn't work and it stops at jshint.
Try npm run watch:js instead of npm watch:js.
I had the same issue with npm in angular2. The build-script:
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"
wouldn't work - but both commands were running standalone. The run solved it for me.