0

I am getting an error for the following package.json file.

If you already have a default version of it. I would be appreciated.

Thanks.

D:\Dev\survey-reactjs>npm run start
npm ERR! code EJSONPARSE
npm ERR! file D:\Dev\survey-reactjs\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 288 while parsing '{
npm ERR! JSON.parse   "name": "survey-reactjs",
npm ERR! JSON.parse   "version'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Asus\AppData\Roaming\npm-cache\_logs\2020-07-16T23_48_39_175Z-debug.log

The updated version is below:

Edit:

D:\Dev\survey-reactjs>npm run start

> survey-reactjs@0.1.0 start D:\Dev\survey-reactjs
> node server.js

internal/modules/cjs/loader.js:969
  throw err;
  ^

Error: Cannot find module 'D:\Dev\survey-reactjs\server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! survey-reactjs@0.1.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the survey-reactjs@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\Asus\AppData\Roaming\npm-cache\_logs\2020-07-17T00_26_04_833Z-debug.log

Package.json file

{
  "name": "survey-reactjs",
  "version": "0.0.2",
  "description": "",
  "main": "''",
  "scripts": {
    "build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
    "dev": "webpack-dev-server --progress --profile --colors --hot"
    "start": "node ./scripts/start.js",
  },
  "dependencies": {
    "json-loader": "^0.5.4",
    "json5-loader": "^0.6.0",
    "jsx-loader": "^0.13.2",
    "node-libs-browser": "1.0.0",
    "react": "15.0.1",
    "react-dom": "15.0.1"
  }
}

The updated version is below.

Edit :

{
  "name": "survey-reactjs",
  "scripts": {
    "start": "node server.js"
  },
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "cra-template": "1.0.3",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-scripts": "3.4.1"
  }
}

I have installed over the scratch but gets different error this time.

Bianca
  • 11
  • 2

2 Answers2

1

This JSON contains two errors:

{
  "name": "survey-reactjs",
  "version": "0.0.2",
  "description": "",
  "main": "''",
  "scripts": {
    "build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
    "dev": "webpack-dev-server --progress --profile --colors --hot"
    "start": "node ./scripts/start.js",
  },
  "dependencies": {
    "json-loader": "^0.5.4",
    "json5-loader": "^0.6.0",
    "jsx-loader": "^0.13.2",
    "node-libs-browser": "1.0.0",
    "react": "15.0.1",
    "react-dom": "15.0.1"
  }
}

It has a missing comma in one place and an extra comma in another place. It should be this:

{
  "name": "survey-reactjs",
  "version": "0.0.2",
  "description": "",
  "main": "''",
  "scripts": {
    "build": "NODE_ENV=production webpack -p --config webpack.production.config.js --progress --profile --colors",
    "dev": "webpack-dev-server --progress --profile --colors --hot",
    "start": "node ./scripts/start.js"
  },
  "dependencies": {
    "json-loader": "^0.5.4",
    "json5-loader": "^0.6.0",
    "jsx-loader": "^0.13.2",
    "node-libs-browser": "1.0.0",
    "react": "15.0.1",
    "react-dom": "15.0.1"
  }
}

A comma was added at the end of the "dev" line and a comma was removed after the "start" line. In the future, you can check your own JSON here: https://jsonlint.com/

jfriend00
  • 580,699
  • 78
  • 809
  • 825
  • I have changed my package.json file in edited version but still gets an error as shown above – Bianca Jul 17 '20 at 00:49
  • 1
    @Bianca - Well, that's a completely different issue. I've answered your question about your JSON and you really shouldn't be turning your question into something different. For that other issue, I'd suggest you read this: [NPM Error code ELIFECYCLE](https://stackoverflow.com/questions/42308879/npm-err-code-elifecycle), but if that and other searches don't help, then you should probably post a new question about that issue where you describe your installation and what you have already tried to fix the ELIFECYCLE issue. – jfriend00 Jul 17 '20 at 01:15
0

This is probably not error with your package.json, If it was no error with your package.json then on npm run start you would not be getting error of module not found, So the error is module not found ! now, which module?

Please look closely at the issue D:\Dev\survey-reactjs\server.js

Please check the following:

  1. Do you have server.js file on the above path directory, if it is there then please do check if you have any package you have used but never installed it through npm install package name

2.if above solution do not give you good result I suggest you try building project from below steps:

Whenever starting a project : Build your package.json from npm init then start installing packages required through npm install then put you server.js file at root directory only

Please note that: Nodejs considers all your installed packages and any of JS file that you write as a seprate module

xoxocoder
  • 204
  • 1
  • 10