I install the packages fine. Now I try and compile the scripts with npm run dev like thus..
terminal
npm run dev
> dev
> npm run development
> development
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
node:events:491
throw er; // Unhandled 'error' event
^
Error: spawn node_modules/webpack/bin/webpack.js ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:291:12)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn node_modules/webpack/bin/webpack.js',
path: 'node_modules/webpack/bin/webpack.js',
spawnargs: [
'--progress',
'--hide-modules',
'--config=node_modules/laravel-mix/setup/webpack.config.js'
]
}
Node.js v19.2.0
terminal
npm -v
8.19.3
package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"lodash": "^4.17.5",
"vue": "^2.5.7",
"vuex": "^3.0.1"
}
}
If you can help me with;-
node:events:491
throw er; // Unhandled 'error' event
thanks in advance
Related
It's be a couple of weeks since I've worked on this specific project, and when I went back to it I can't get npm dev, which is what I had been using to run the server to work. I've also tried npm run dev and that doesn't work either. I keep getting an error stating:
> amos#1.0.0 dev
> cross-env NODE_ENV=dev nodemon src/index.js
node:events:371
throw er; // Unhandled 'error' event
^
Error: spawn nodemon ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:480:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
at onErrorNT (node:internal/child_process:480:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn nodemon',
path: 'nodemon',
spawnargs: [ 'src/index.js' ]
}
I tried deleting node_modules and package-lock.json and re-installing them a couple of times. I have also tried to force clear the cache. I'm really not sure what else to try, and I would really appreciate any help or advice. Thank you!
package.json
{
"name": "amos",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "cross-env NODE_ENV=dev nodemon src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-express": "^3.8.2",
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"braces": "^3.0.2",
"cross-env": "^7.0.3",
"express": "^4.18.1",
"graphql": "^16.5.0",
"graphql-tools": "^8.2.12",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.3.6"
}
}
I am trying to run some React code on my server-side using node. Following a tutorial, I am trying to add babel to my node server so that JSX gets transpiled to JS.
I added the run scripts to my json.config to use babel-node as below (I use the "watch-server" script for development):
"scripts": {
"start": "start:dev",
"server": "node babel-node ./server/index.js",
"start:dev": "webpack && npm run server",
"start:prod": "webpack && npm run server",
"test": "jest",
"test:debug": "jest --debug",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage --colors",
"watch-server": "nodemon -e js,scss,jsx --ignore '*.bundle*.js' --verbose --exec npm run start:dev"
The issue I get is when I try to run npm run watch-server is an error:
> node babel-node ./server/index.js
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module '/Users/zarnowm/Documents/GitHub/dsr-ux/babel-node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Here is a snippet of my dependencies:
"devDependencies": {
"#babel/core": "^7.4.3",
"#babel/node": "^7.14.9",
"#babel/plugin-proposal-class-properties": "^7.4.0",
"#babel/plugin-proposal-object-rest-spread": "^7.4.3",
"#babel/plugin-transform-runtime": "^7.4.3",
"#babel/preset-env": "^7.4.3",
"#babel/preset-react": "^7.0.0",
"#babel/runtime": "^7.5.0",
And .babelrc:
{
"env": {
"test": {
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
"#babel/plugin-proposal-class-properties",
"#babel/plugin-proposal-object-rest-spread",
"#babel/plugin-transform-runtime"
]
}
}
}
Im struggling to figure out the issue...
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.
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",
},
...
Im having issues getting my build on heroku to work. Heroku is saying the build succeeded but when I pull up the page I get the Application Error page.
Here is my package.JSON for the React
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.5.1",
"express": "^4.16.3",
"firebase": "^4.8.1",
"moment": "^2.22.1",
"nodemailer": "^4.6.5",
"nodemon": "^1.17.5",
"re-base": "^3.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"node-sass": "^4.7.2",
"react-scripts": "1.0.17",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
and for the node.js
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^3.5.1",
"express": "^4.16.3",
"firebase": "^4.8.1",
"moment": "^2.22.1",
"nodemailer": "^4.6.5",
"nodemon": "^1.17.5",
"re-base": "^3.2.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"node-sass": "^4.7.2",
"react-scripts": "1.0.17",
"redux": "^3.7.2",
"sass-loader": "^6.0.6",
"webpack": "^3.10.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
In the logs, I am getting an error that react-scripts are failing in the Heroku build process. The node and the react are getting fired but it fails soon after that.
And here are the heroku logs
2018-06-13T12:56:17.879178+00:00 app[web.1]: [1] sh: 1: react-scripts: not found
2018-06-13T12:56:17.910185+00:00 app[web.1]: [1] npm ERR! file sh
2018-06-13T12:56:17.910189+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.912160+00:00 app[web.1]: [1] npm ERR! errno ENOENT
2018-06-13T12:56:17.913985+00:00 app[web.1]: [1] npm ERR! syscall spawn
2018-06-13T12:56:17.922554+00:00 app[web.1]: [1] npm ERR! cloudveilheli#0.1.0 start: `react-scripts start`
2018-06-13T12:56:17.927487+00:00 app[web.1]: [1] npm ERR! spawn ENOENT
2018-06-13T12:56:17.928818+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:17.932398+00:00 app[web.1]: [1] npm ERR! Failed at the cloudveilheli#0.1.0 start script.
2018-06-13T12:56:17.932401+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:17.967183+00:00 app[web.1]: [1] npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2018-06-13T12:56:17.968219+00:00 app[web.1]: [1]
2018-06-13T12:56:17.968222+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:17.968224+00:00 app[web.1]: [1] npm ERR! /app/.npm/_logs/2018-06-13T12_56_17_935Z-debug.log
2018-06-13T12:56:17.992492+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.992495+00:00 app[web.1]: [1] npm ERR! errno 1
2018-06-13T12:56:17.996672+00:00 app[web.1]: [1] npm ERR! bluebirdheliapp#1.0.0 client: `npm run start --prefix cloudveil_heli_app`
2018-06-13T12:56:17.999397+00:00 app[web.1]: [1] npm ERR! Exit status 1
2018-06-13T12:56:18.004427+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:18.004430+00:00 app[web.1]: [1] npm ERR! Failed at the bluebirdheliapp#1.0.0 client script.
2018-06-13T12:56:18.004432+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:18.021046+00:00 app[web.1]: [1]
2018-06-13T12:56:18.021050+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:18.021052+00:00 app[web.1]: [1] npm ERR! /app/.npm/_logs/2018-06-13T12_56_18_005Z-debug.log
2018-06-13T12:56:18.046560+00:00 app[web.1]: [1] npm run client exited with code 1
while you push your app to heroku
first it runs npm install
later it runs npm start
so we have to declare in package.json what to run after npm install is completed and what npm start need to do.
update you package.json with:
{
"name": "cloudveilheli",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001",
"scripts": {
"start": "node server.js",
"postinstall": "npm start build "
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
where postinstall works after the npminstall is completed
and create a server.js file like this:
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/dist'));
app.all('*', (req, res) => {
res.status(200).sendFile(__dirname + '/dist/index.html');
});
app.listen(process.env.PORT || 8080);
at dist/index.html give where index.html created in react
as i dont know react