npm run dev command is not working with the following configurations - node.js

I'm following this tutorials for my first TDD project: https://medium.com/developer-circles-lusaka/how-to-write-an-express-js-server-using-test-driven-development-921dc55aec07
I have install all the required dependency and my package.json file looks like below.
{
"name": "lms_webapi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "babel src -d dist --source-maps",
"serve": "NODE_ENV=production node dist/index.js",
"start": "NODE_ENV=development babel-node src/index.js",
"dev": "DEBUG=server:debug NODE_ENV=development nodemon src/index.js --exec babel-node",
"test": "DEBUG=server:debug NODE_ENV=test mocha --require babel-core/register --reporter spec --exit tests/ --exec babel-node",
"test:watch": "DEBUG=server:debug NODE_ENV=development mocha --require babel-core/register --watch --reporter spec tests/ --exec babel-node",
"eslint": "eslint src/**/*.js --ignore-pattern \"node_modules/\""
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-cli": "^6.26.0",
"babel-preset-node8": "^1.2.0",
"chai": "^4.2.0",
"config": "^3.3.1",
"debug": "^4.1.1",
"express": "^4.17.1",
"mocha": "^7.1.1",
"mongoose": "^5.9.7",
"supertest": "^4.0.2"
},
"babel": {
"presets": [
"node8"
]
},
"engines": {
"node": ">=8"
},
"eslintConfig": {
"plugins": [
"node"
],
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"rules": {
"node/no-unsupported-features/es-syntax": 0,
"node/no-unsupported-features/es-builtins": 0
},
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018
}
}
}
after running the command npm run dev from terminal, I got the following error.
lms_webapi#1.0.0 dev E:\Test\LMS_WebAPI
DEBUG=server:debug NODE_ENV=development nodemon src/index.js --exec babel-node
Der command "DEBUG" is either false or not found.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lms_webapi#1.0.0 dev: DEBUG=server:debug NODE_ENV=development nodemon src/index.js --exec babel-node
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lms_webapi#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Your help will be highly appreciated.
Thank you!

The dev-script fails because it tries to look for the DEBUG command instead of setting the environment variable. This tells us that you're probably on a windows machine. Hence, you need can adjust setting the env-variables as follows:
...
"scripts": {
...
"dev": "set DEBUG=server:debug && set NODE_ENV=development && nodemon src/index.js --exec babel-node",
},
...

Related

Why do i get an error react-scripts: not found on github actions CI

I have the following package.json files for my app:
Client folder:
``{
"name": "nasa-fe",
"version": "1.0.1",
"private": true,
"dependencies": {
"arwes": "^1.0.0-alpha.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.8.0",
"react-scripts": "^5.0.1"
},
"overrides": {
"nth-check#1.0.2": "2.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "set BUILD_PATH=../server/public&& react-scripts build",
"test": "react-scripts test --passWithNoTests",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Server folder:
{
"name": "nasa-project-api",
"version": "1.0.0",
"description": "Nasa mission control api",
"main": "src/server.js",
"scripts": {
"test": "jest --detectOpenHandles",
"test-watch": "jest --watch",
"watch": "nodemon src/server.js",
"start": "node src/server.js",
"cluster": "pm2 start src/server.js -i max"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"csv-parse": "^5.3.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mongoose": "^6.8.4",
"mongose": "^0.0.2-security",
"morgan": "^1.10.0",
"pm2": "^5.2.2",
"react-router-dom": "^6.8.0",
"react-scripts": "^5.0.1"
},
"devDependencies": {
"jest": "^29.3.1",
"nodemon": "^2.0.20",
"supertest": "^6.3.3"
}
}
and root folder:
{
"name": "nasa-exploration",
"version": "1.0.0",
"description": "This a full stack project",
"main": "index.js",
"scripts": {
"deploy": "set BUILD_PATH=../server/public && npm run build --prefix client && npm start --prefix server",
"deploy-cluster": "npm run build --prefix client && npm run cluster --prefix server",
"server": "npm run watch --prefix server",
"client": "npm start --prefix client",
"watch": "npm run server & npm run client",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/yayoamigo/Nasa-exploration.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/yayoamigo/Nasa-exploration/issues"
},
"homepage": "https://github.com/yayoamigo/Nasa-exploration#readme",
"dependencies": {
"arwes": "^1.0.0-alpha.5",
"axios": "^1.2.4",
"dotenv": "^16.0.3",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.0",
"react-scripts": "^5.0.1"
}
}
as you can see I have react-scripts in every folder but get this error regardless, I tried to reinstall the dependencies, change the scripts and nothing. The weird things is when I npm run build on my PC it works
Just checked the Workflow in your repo and I see that you are running the following commands:
...
- run: npm install
- run: npm run build --prefix client
...
According to this, the npm run build --prefix client will run the build under the client directory, but the first command installs dependencies under the root folder. The build just can't find dependencies since it's not installed in the client directory.
So you need to change your install command to use the prefix also:
npm install --prefix client
To read more about prefixes, visit the official docs.
Alternatively, you can use the working-directory keyword to specify the working directory of where to run the command:
- name: Install
working-directory: client
run: npm install
- name: Build
working-directory: client
run: npm run build

Trying to run "npm run devStart" on mac

This is my package.json
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"devStart": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.1",
"express": "^4.17.2",
"mysql": "^2.18.1"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
When trying to run npm run devStart on visual studio code terminal for mac I get the following errors
% npm run devStart
npm ERR! Missing script: "devStart"
npm ERR! Did you mean this?
npm ERR! npm restart # Restart a package
npm ERR! To see a list of scripts, run:
npm ERR! npm run
...

npm no such file or directory when trying to run 'npm run deploy'

I get this error:
no such file or directory, stat 'C:\Users\nessa\VS Code\React-Django\website\frontend\build'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend#1.0.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend#1.0.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
when trying to run npm run deploy.
This is my package.json file located in my .\website\frontend
{
"name": "frontend",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"start": "react-scripts start",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.13.13",
"#babel/preset-env": "^7.13.12",
"#babel/preset-react": "^7.13.13",
"babel-loader": "^8.2.2",
"css-loader": "^5.2.0",
"gh-pages": "^3.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"style-loader": "^2.0.0",
"webpack": "^5.28.0",
"webpack-cli": "^4.6.0"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.13.0",
"#material-ui/core": "^4.11.3",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.57",
"react-material-ui-carousel": "^2.2.4",
"react-router-dom": "^5.2.0",
"react-speech": "^1.0.2"
}
}
I've been running npm run dev from the same location all the time without issues. I'm trying to host my react app on Github. I tried reinstalling gh-pages in case a file didn't properly install but am having the same problems. What should I do to resolve this?
Edit: I tried to do what was said here, but still didn't work. Here's my webpack.config.js if that helps.
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, './static/frontend'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
optimization: {
minimize: true,
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
}
I also changed "build": "webpack --mode production" in my package.json scripts to "build": "webpack --mode development", in order to run npm run build, but the problem still isn't fixed.
This was my error:
ENOENT: no such file or directory, stat 'C:\Users...\dist'
So I added
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
on package.json in "scripts".
And run the command npm install gh-pages --save-dev in terminal.
Finishing with npm run deploy.
After you add predeploy, deploy in script in JSON file.
run : npm run build
run : npm run deploy

React server (front-end) is blocking express server (back-end)

Here is my package.json file
{
"name": "crypto",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "jest --watchAll",
"start": "npm run build-client && node index.js",
"dev": "npm run dev-client & npm run start-redis && cross-env ENV='development' nodemon index.js",
"dev-peer": "cross-env GENERATE_PEER_PORT='true' ENV='development' nodemon index.js",
"start-redis": "redis-server --daemonize yes",
"build-client": "npm run clean && parcel build client/src/index.html --out-dir client/dist",
"dev-client": "npm run clean && parcel client/src/index.html --out-dir client/dist",
"clean": "rm -rf .cache client/dist"
},
"jest": {
"testEnvironment": "node"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"cross-env": "^7.0.2",
"jest": "^26.0.1",
"nodemon": "^2.0.4"
},
"dependencies": {
"body-parser": "^1.19.0",
"elliptic": "^6.5.3",
"express": "^4.17.1",
"hex-to-binary": "^1.0.1",
"parcel-bundler": "^1.12.4",
"pubnub": "^4.28.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"redis": "^3.0.2",
"request": "^2.88.2",
"uuid": "^3.3.2"
},
"description": ""
}
When i run command npm run dev, i receive following Result,
$ npm run dev
crypto#1.0.0 dev C:\Users\Education Use\crypto
npm run dev-client & npm run start-redis && cross-env ENV='development' nodemon index.js
crypto#1.0.0 dev-client C:\Users\Education Use\crypto
npm run clean && parcel client/src/index.html --out-dir client/dist
crypto#1.0.0 clean C:\Users\Education Use\crypto
rm -rf .cache client/dist
Server running at http://localhost:1234
✨ Built in 107.61s.
that is only running dev-client and blocking epress server.
Guide me please...

Errors on 'concurrently "npm run server" "npm run client" with MERN

First of all, I would like to apologize for the spelling mistakes, I'm not very good.
I have a problem whilethe starting my mern server...
I want to run it with with "npm run dev". This command line execute "npm run server" and "npm run client".
Here's my errors :
C:\Users\Jérémy\Desktop\Rendu\MERN\MERN_d04>npm run dev
mern_d04#1.0.0 dev C:\Users\Jérémy\Desktop\Rendu\MERN\MERN_d04
concurrently "npm run server" "npm run client"
[0] Error occurred when executing command: npm run server
[0] Error: spawn cmd.exe ENOENT
[0] at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[0] at onErrorNT (internal/child_process.js:467:16)
[0] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] Error occurred when executing command: npm run client
[1] Error: spawn cmd.exe ENOENT
[1] at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[1] at onErrorNT (internal/child_process.js:467:16)
[1] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] npm run client exited with code -4058
[0] npm run server exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mern_d04#1.0.0 dev: `concurrently "npm run server" "npm run client"`>npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mern_d04#1.0.0 dev 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\Jérémy\AppData\Roaming\npm-cache\_logs\2020-04-22T19_45_03_286Z-debug.log
And Here's, my root package.json :
{
"name": "mern_d04",
"version": "1.0.0",
"description": "",
"main": "server.js",
"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\""
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"concurrently": "^5.1.0",
"express": "^4.17.1",
"is-empty": "^1.2.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.10",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"validator": "^13.0.0"
},
"devDependencies": {
"nodemon": "^2.0.3"
}
}
And here's my client package.json :
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"classnames": "^2.2.6",
"jwt-decode": "^2.2.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"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"
]
}
}
I've tried many things and, the most surprising thing is : it works on the computer of my friend but not mines.
Please someone can help me? :)
EDIT : Node version : 13.0.0
EDIT : Found the solution. I "just" had a variable "C:\Windows\System32" in the environment variables :)
I was facing the same problem.
for this code works, you can try this.. on your root package.json
"scripts": {
"start": "node index",
"server": "nodemon index",
"client": "npm run start --prefix client",
"dev": "concurrently \"npm run server\" \"cd client && npm start\""
},
and then from root directory type npm run dev
The node_modules are not compatible with your current systems. You may remove the node_modules folders at the root level AS WELL AS at the client level. Then you install both node_modules AGAIN.

Resources