Home > Net >  When running a script - Error no test specified appears. How do I make the script run correctly?
When running a script - Error no test specified appears. How do I make the script run correctly?

Time:10-04

I am trying to run a React script for game and I have been following a tutorial online ( I am very new to all programming). Every time I try to run some code to work on port 8000 I get this that pops up:

Debugger attached.
Lifecycle scripts included in [email protected]:
test
echo "Error: no test specified" && exit 1

Waiting for the debugger to disconnect...

This is my package.json file

{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "app.js",
"dependencies": {
  "express": "4.17.1",
  "socket.io": "2.3.0"
},
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

I run it in the terminal through npm run.

I have tried other resolves on other questions I have found like Jest or Mocha and none of that has worked.

Thank you for your help:)

CodePudding user response:

When you execute npm run, you have to specify the script you want to run from the scripts section(i.e. npm run test).

According to your problem, I think when you didn't put the script name and just run npm run, it might have run the first script under the scripts section of package.json(If you want, you can specifically run that command using npm run test).

So if you want to run a node server you can set up a script in the package.json as follows

{
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
}

You may change the file name if you have used a different name than the server.js. Then You can run the above script using npm run start.

If you want to run a react script, you can do the same thing as follows.

{
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "do": "react-scripts <script_name>"
  },
}

and npm run do.

Please note that in order to run the above command you have to install necessary packages such as react, react-scripts, etc...

For more info on react-scripts, please checkout here!

  • Related