My question is simple How to run a server node js and a react app in same time?
My package.json
{
"name": "mon-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"express": "^4.17.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-scripts": "0.9.5"
},
"devDependencies": {
"concurrently": "^2.2.0"
},
"scripts": {
"start": "concurrently \"node server.js\" \"react-scripts start\"",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
I use concurrently
Moreover npm start runs of course the dev server
Thanks for your help :)
you can try doing something like this:
{
"name": "mon-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"express": "^4.17.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-scripts": "0.9.5"
},
"devDependencies": {
"concurrently": "^2.2.0"
},
"scripts": {
"server": "node server.js",
"client": "react-scripts start",
"start": "concurrently \"npm run server\" \"npm run client\"",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
does that solve your problem?
Related
Working on a yarn2 powered monorepo with two workspaces common and app. I've declared typescript and react-scripts as devDependencies in root's package.json ; and declared typescript and react-scripts as peerDependencies in app's package.json.
However, running yarn start gives the error
command not found: react-scripts
Any idea how to go about this?
Sidenote
react-scripts has peerDependencies on react which I've provided in root workspace's dependency section.
attaching package.json for root:
{
"name": "monorepo",
"packageManager": "yarn#3.2.1",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"#types/jest": "^27.5.2",
"#types/node": "^16.11.43",
"#types/react": "^18.0.15",
"#types/react-dom": "^18.0.6",
"fictoan-react": "^0.41.22",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"react-scripts": "5.0.1",
"typescript": "^4.7.4"
},
"workspaces": [
"common",
"app"
]
}
package.json for app
{
"name": "app",
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"dependencies": {
"common": "workspace:*"
},
"peerDependencies": {
"#testing-library/jest-dom": "*",
"#testing-library/react": "*",
"#testing-library/user-event": "*",
"#types/jest": "*",
"#types/node": "*",
"#types/react": "*",
"#types/react-dom": "*",
"fictoan-react": "*",
"react": "*",
"react-dom": "*",
"react-scripts": "*",
"styled-components": "*",
"web-vitals": "*"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Not sure if this is a hack, but solved this using https://yarnpkg.com/getting-started/qa#how-to-share-scripts-between-workspaces
added this to root's package.json
"scripts": {
"g:start": "cd $INIT_CWD && react-scripts start",
"g:build": "cd $INIT_CWD && react-scripts build",
"g:test": "cd $INIT_CWD && react-scripts test",
"g:eject": "cd $INIT_CWD && react-scripts eject"
}
updated this in app's package.json
"scripts": {
"start": "yarn g:start",
"build": "yarn g:build",
"test": "yarn g:test",
"eject": "yarn g:eject"
}
PS:not really sure why react-scripts isn't available in app workspace even though its specified as a peerDependency :/
I've been working on a project, but when I try to build it I got the following error:
Failed to minify the code from this file:
./node_modules/emailjs-com/es/utils/validateParams.js:1:7
I am using craco to build the project. I have researched about this error, but I was not able to make any of the solutions I found work on my case.
My package.json:
{
"name": "my-portfolio",
"version": "0.1.0",
"private": true,
"dependencies": {
"-": "^0.0.1",
"#craco/craco": "^5.9.0",
"#fortawesome/fontawesome-svg-core": "^1.2.35",
"#fortawesome/free-brands-svg-icons": "^5.15.3",
"#fortawesome/free-solid-svg-icons": "^5.15.3",
"#fortawesome/react-fontawesome": "^0.1.14",
"#heroicons/react": "^1.0.1",
"dotenv": "^10.0.0",
"emailjs": "^3.5.0",
"emailjs-com": "^3.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0",
"react-icons": "^4.2.0",
"react-scripts": "^1.1.5",
"save-dev": "^0.0.1-security"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"devDependencies": {
"autoprefixer": "^9.8.6",
"gh-pages": "^3.2.3",
"postcss": "^7.0.36",
"tailwindcss": "npm:#tailwindcss/postcss7-compat#^2.0.2"
}
}
I would like to know if there is a way to build it without executing any minification, or if it is really required, how to solve the minification that I am having when trying to minify my code.
I made the react app using create-react-app and installed firebase : 8.2.3, but while importing firebase in App.js I am getting error "Cannot use import statement outside a module" and my app doesn't run.
here are my package.json configuration:
{
"name": "sample-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"firebase": "^8.2.3",
"gh-pages": "^3.1.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-lazyload": "^3.1.0",
"react-lines-ellipsis": "^0.14.1",
"react-router-dom": "^5.2.0",
"react-scripts": "0.9.x",
"react-test-renderer": "^17.0.1",
"zustand": "^3.1.4"
},
"devDependencies": {},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
}
Used create-react-app template. Windows, OpenServer.
package.json
{
"name": "league-finder",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"pre-commit": "lint-staged",
"eslint": "./node_modules/.bin/eslint src/"
},
"devDependencies": {
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-prettier": "^2.7.0",
"husky": "^1.0.1",
"lint-staged": "^7.3.0",
"prettier": "^1.14.3"
}
}
.lintstagedrc
{
"*.js": ["eslint --fix", "git add"],
}
Result: screenshot
Why "No staged files match *.js"?
When running npm start I get this error
Cannot find module 'react-dev-utils/WebpackDevServerUtils'
I even tried deleting and reinstalling. Any help? Here's package.json
{
"name": "tic-tac-toe-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4",
"webpack": "^4.15.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"react-dev-utils": "^5.0.1",
"react-scripts": "^1.1.4",
"webpack": "^1.15.0",
"webpack-cli": "^3.0.8",
"webpack-command": "^0.4.1",
"webpack-dev-server": "^3.1.4"
}
}
Delete the "node_modules' folder within the project
Then run npm install again