简体   繁体   中英

Unable to run scripts on npm from fresh install

Alright, so I freshly installed NodeJS 9.5.0 and double-checked to see that npm is on the most updated version (5.6.0), and so far I've been having issues with running a simple script from the package.json file.

Here's what I have under the package.json file.

{
  "name": "hello_world",
  "version": "1.0.0",
  "description": "lab-4-hello-world-app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
    "start": "node index.js"
  },
  "author": "Java Drinker",
  "license": "ISC"
}

And here is my index.js . Thankfully, Node is able to run it just fine from cli.

    console.log("Hello Java Drinker!");

Below this is the error message I received from trying to run the "start" script with the debug log following it.

npm ERR! file C:\test\package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected string in JSON at position 187 while parsing '{
npm ERR!   "name": "hello_world",
npm ERR!   "version": '
npm ERR! File: C:\test\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! Tell the package author to fix their package.json file. JSON.parse

2018-02-22T07_49_53_423Z-debug.log

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'start' ]
2 info using npm@5.6.0
3 info using node@v9.5.0
4 verbose stack Error: Failed to parse json
4 verbose stack Unexpected string in JSON at position 187 while parsing '{
4 verbose stack   "name": "hello_world",
4 verbose stack   "version": '
4 verbose stack     at parseError (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:436:11)
4 verbose stack     at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:104:26)
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:51:5
4 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16
4 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)
5 verbose cwd C:\test
6 verbose Windows_NT 10.0.16299
7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start"
8 verbose node v9.5.0
9 verbose npm  v5.6.0
10 error file C:\test\package.json
11 error code EJSONPARSE
12 error Failed to parse json
12 error Unexpected string in JSON at position 187 while parsing '{
12 error   "name": "hello_world",
12 error   "version": '
13 error File: C:\test\package.json
14 error Failed to parse package.json data.
14 error package.json must be actual JSON, not just JavaScript.
14 error
14 error Tell the package author to fix their package.json file. JSON.parse
15 verbose exit [ 1, true ]

I'd like to add that I can run npm -v just fine.. but it seems like any other command just causes errors for me. I guess I'm installing npm incorrectly..?

Make sure your package.json file is valid . In the provided sample, you need to add a missing comma , after the test script (end of line 6):

{
  "name": "hello_world",
  "version": "1.0.0",
  "description": "lab-4-hello-world-app",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "author": "Java Drinker",
  "license": "ISC"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM