user10285972
user10285972

Reputation:

I can't get react up and running. When i type npm start then it gives me an error

As you can see i get this error. Has it something to do with my package.json? Default looks like this.

{
    "name": "reactproject",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "react": "^16.12.0",
        "react-dom": "^16.12.0",
        "react-scripts": "3.3.0"
    }
}
npm ERR! missing script: start

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\k12\AppData\Roaming\npm-cache\_logs\2019-12-31T00_09_26_886Z-debug.log
PS C:\Users\k12\reactproject> ^C

After i did the command npm rm -g create-react-app i get the following in the command prompt

Error: EPERM: operation not permitted, mkdir 'C:\Users\k12'
TypeError: Cannot read property 'get' of undefined
    at errorMessage (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-message.js:38:39)
    at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:201:13)
    at C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js:78:20
    at cb (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:225:22)
    at C:\Program Files\nodejs\node_modules\npm\lib\npm.js:263:24
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:81:7
    at Array.forEach (<anonymous>)
    at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:80:13
    at f (C:\Program Files\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:171:20)
C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:97:27)
    at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:210:5)
    at process._fatalException (internal/process/execution.js:150:25)
Install for [ 'create-react-app@latest' ] failed with code 7

C:\Users\k12>

Upvotes: 0

Views: 2138

Answers (2)

Pete TNT
Pete TNT

Reputation: 8403

Looking at your package.json, your project seems to be a Create React App project without a template. This occurs when you have an older, globally installed CRA on your machine. The default template package.json should look like this:

{
  "name": "test3",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.3.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"
    ]
  }
}

Remove the globally installed version (npm rm -g create-react-app) and try again with npx create-react-app reactproject

See the https://create-react-app.dev/docs/getting-started guide for more information.

Upvotes: 0

T. Short
T. Short

Reputation: 3614

The error is because you have no start script defined in your package.json

As I don't know what your server set up is, I cannot say what is should be exactly. But something along the lines of:

"scripts": {
    "start": "node index.js",
}

Upvotes: 0

Related Questions