2

i am trying to create a react app by using NPX create react app and npm install runs fine but npm start which is supposed to run the code gives error.

Here is the error

> react-scripts start

i 「wds」: Project is running at http://10.54.83.144/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\xyz\Desktop\app\my-app\public
i 「wds」: 404s will fallback to /
Starting the development server...

events.js:288
      throw er; // Unhandled 'error' event
      ^

Error: spawn cmd ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn cmd',
  path: 'cmd',
  spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000"' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@0.1.0 start 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\xyz\AppData\Roaming\npm-cache\_logs\2020-03-09T20_33_16_720Z-debug.log

here is the package.json

{
  "name": "my-app",
  "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",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-scripts": "^3.4.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "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"
    ]
  }
}

Here is full debug log file.

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\xyz\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.2
3 info using node@v12.16.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle my-app@0.1.0~prestart: my-app@0.1.0
6 info lifecycle my-app@0.1.0~start: my-app@0.1.0
7 verbose lifecycle my-app@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle my-app@0.1.0~start: PATH: C:\Users\xyz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\xyz\Desktop\app\my-app\node_modules\.bin;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files\RSA SecurID Token Common;C:\apache\maven3.6.1\bin;C:\Program Files\Java\jdk1.8.0_241\bin;C:\Program Files\nodejs\;C:\Users\xyz\AppData\Local\Microsoft\WindowsApps;;C:\Users\xyz\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\xyz\AppData\Roaming\npm
9 verbose lifecycle my-app@0.1.0~start: CWD: C:\Users\xyz\Desktop\app\my-app
10 silly lifecycle my-app@0.1.0~start: Args: [ '/d /s /c', 'react-scripts start' ]
11 silly lifecycle my-app@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle my-app@0.1.0~start: Failed to exec start script
13 verbose stack Error: my-app@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\xyz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:311:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\xyz\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:311:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid my-app@0.1.0
15 verbose cwd C:\Users\xyz\Desktop\app\my-app
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\xyz\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.16.1
19 verbose npm  v6.14.2
20 error code ELIFECYCLE
21 error errno 1
22 error my-app@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the my-app@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

i tried deleting the node modules and removing cache then using NPM INSTALL again But they did not work.what am i missing here?

raju
  • 209
  • 7
  • 19
  • It looks like you're calling `react-scripts start`, not `npm start`. Aside from that, this looks like a duplicate of [Using nodejs's spawn causes "unknown option -- " and "\[Error: spawn ENOENT\]" errors](https://stackoverflow.com/questions/17516772/using-nodejss-spawn-causes-unknown-option-and-error-spawn-enoent-err) because you're trying to run `npm` on windows through spawn, but you forgot to tell Node to use `npm.cmd` (because "npm" is not an executable on windows) – Mike 'Pomax' Kamermans Mar 09 '20 at 20:55
  • i used npm start on my terminal @Mike 'Pomax' Kamermans – raju Mar 09 '20 at 20:57
  • then it looks like whoever made `react-scripts` forgot that Windows exists, and you should probably file a bug on their issue tracker (after searching it, to make sure it's not an already known problem, with an already known workaround) – Mike 'Pomax' Kamermans Mar 09 '20 at 21:00
  • Try to install/updating things like nodejs and make sure they are updated. `sudo apt-get update nodejs` (might be node.js) You could also try `npm update` – Greg M Mar 09 '20 at 21:15

2 Answers2

3

Solution 1

Set your environment variable to C:\Windows\System32.

Solution 2

If the first one doesn't work follow the 2nd steps. Navigate to your project folder and type this command >>>

rm -rf node_modules

rm package-lock.json

rm yarn.lock

npm cache clear --force

npm install

Solution 3

Downgrade react-scripts in package.json file

Vivek Anand
  • 1,264
  • 8
  • 15
0

I would say first try the below code to create an npm project and your react app then once that starts you can try to ammend the package.json to your needs

npx create-react-app my-app cd my-app npm start

Rester Test
  • 227
  • 2
  • 10
  • i did not amend my package.json. i just used npx create-react-app my-app cd my-app npm start as you said and it gives this error. – raju Mar 09 '20 at 21:00