0

The package.json is:

{
  "scripts": {
    "test": "find ./js/tests -name '*.test.js' | xargs mocha -R spec",
    "start": "node ./scores.js",
    "run": "node ./scores.js"
  },
  "dependencies": {
    "aws-sdk": "^2.734.0",
    "body-parser": "^1.19.0",
    .. 
    "dotenv": "^8.2.0"
  },
  "name": "scores",
  "version": "1.0.0",
  "main": "",
  "repository": {
    "type": "git",
    "url": "something"
  }
}

npm install has been done and the package-lock.json created. Why are either npm run or npm run-script working?

$npm run-script ./scores.js
npm ERR! missing script: ./scores.js

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/steve/.npm/_logs/2021-03-01T23_01_56_745Z-debug.log
15:01:56/scores $ls -l scores.js
-rw-r--r--  1 steve  staff  21417 Feb 25 06:24 scores.js

I have identically structured package.json and scripts in other sibling directories that do work e.g. the following works via cd ../keys_server; npm run keys_server

$cat ../keys_server/package.json
{
  "scripts": {
    "test": "find ./js/tests -name '*.test.js' | xargs mocha -R spec",
    "keys_server": "node ./keys_server.js",
    "start": "node ./keys_server.js"
  },
  "dependencies": {
    "aws-sdk": "^2.734.0",
    "body-parser": "^1.19.0",
    "express": "^4.17.1",
      ..
    "dotenv": "^8.2.0"
  },
  "name": "keys_server",
  "version": "1.0.0",
  "main": "keys_server.js",
  "repository": {
    "type": "git",
    "url": "something"
  },

Update @pkumar noticed that the main entry was left empty. I now updated it to :

  "main": "scores.js",

and then tried both

npm run-script ./scores.js and npm run scores and npm run scores.js. However none of them work:

$npm run scores

npm ERR! missing script: scores

1 Answer 1

1

The 'main' field is empty in package.json. try adding scores.js there and see if it works

The 'main' field is supposed to be the entry point of the server: https://docs.npmjs.com/cli/v7/configuring-npm/package-json

EDIT: The actual reason it's not working is because "scores" had not been defined under the scripts section. After adding that definition it should work

"scripts": {
      ..
      "scores": "node ./scores.js"
    }
Sign up to request clarification or add additional context in comments.

5 Comments

hmmm after fixing by "main" : "scores.js" and invoking either npm run-script ./scores.js or npm run score it is still not working. I'm looking more..
Maybe you can compare the keys_server.js and scores.is files and see where the files differ. If it works in keys_server there's no reason for it to not work in scores.js
Turns out the main was not the issue: it's under "scripts" section: this should be added ` "scores": "node ./scores.js"` . Why don't you update your answer and then you can get your first "win"
Updated my answer
Please explicitly add to your answer "Should be added under the scripts section : "scores": "node ./scores.js" . Nmd I added it already.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.