39

I am learning reactjs - nodejs I was trying to run the server so I installed yarn, nodemon, express but when I try to run its saying error Command failed with exit code 1.

my error is

    PS D:\react project\ReactManagement-tutorial> yarn dev
yarn run v1.13.0
warning package.json: No license field
$ concurrently --kill-others-on-fail "yarn server" "yarn client"
warning package.json: No license field
warning package.json: No license field
$ nodemon server.js
$ cd client && yarn start
warning ..\package.json: No license field
$ react-scripts start
[1] 'react-scripts'��(��) ���� �Ǵ� �ܺ� ����, ���
��� �� �ִ� ���α׷�, �Ǵ�
[1] ��ġ ������ �ƴմϴ�.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
[1] yarn client exited with code 1
--> Sending SIGTERM to other processes..
[0] yarn server exited with code 1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS D:\react project\ReactManagement-tutorial>

my package.json is

{
    "name": "management",
    "version": "1.0.0",
    "scripts": {
        "client": "cd client && yarn start",
        "server": "nodemon server.js",
        "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn client\""
    },
    "dependencies": {
        "body-parser": "^1.18.3",
        "express": "^4.16.4",
        "nodemon": "^1.18.10"
    },
    "devDependencies": {
        "concurrently": "^4.1.0"
    }
}

and its my server.js

const express = require('express');
const bodyParser = require('body-parser');  //서버모듈을위한 
const app = express();
const port = process.env.PORT || 5000;  
 
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true})); 

app.get('/api/hello',(req,res) =>{  
    res.send({message : 'hello express!'});  
});
app.listen(port,()=>console.log(`listening on port ${port}`))
S. Hesam
  • 5,266
  • 3
  • 37
  • 59
hwiba
  • 413
  • 1
  • 4
  • 8

11 Answers11

49

what you need to do is just simple: follow these steps:

  1. rm -rf node_modules
  2. yarn cache clean
  3. yarn
  4. yarn start
Shailesh kala
  • 1,618
  • 18
  • 16
  • 3
    Just wondering if there's any explanation behind that? Thanks – Zanecola Aug 20 '20 at 03:44
  • 1
    Basically there might be an issue with the wrongly fetched dependency or something happened during transmission. Shailesh advised you removed fetched dependencies, clean yarn cache (sometimes that could be a it) and start fetching dependencies from the start. – Malakai Apr 19 '21 at 19:48
  • 2
    after all 4 steps I got the same error. How can I fix it? – glushkina1 Feb 07 '22 at 14:49
  • "Have you tried to turn it off and on again?" --> Why is literally 50%+ of all those yarn problems more or less the same... – harry Oct 20 '22 at 07:14
8

I faced the same error and I fixed it by following these steps:

  1. Delete yarn.lock or rm -rf yarn.lock (if you are Linux/MacOS user)
  2. Delete node_modules/ or rm -rf node_modules/ (if you are Linux/MacOS user)
  3. Follow the instructions to install the latest Yarn package available from here
  4. Try executing the following commands in your project root folder:

yarn install and yarn start

In case the above approach didn't help:

  1. Try to install the latest node.js
  2. Remove node_modules/ and lock file
  3. use npm install and npm run-script
Abraham
  • 8,525
  • 5
  • 47
  • 53
Karthikaeyan
  • 655
  • 1
  • 9
  • 13
6

This worked for me, (update yarn)

$ yarn info 
$ yarn upgrade 
$ yarn add yarn 

if it shows more errors run this:

export NODE_OPTIONS=--openssl-legacy-provider

Done

Byusa
  • 2,279
  • 1
  • 16
  • 21
3

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try:

  1. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.

  2. Check if C:\Users\nouss\OneDrive\Images\SocialM\react-social\node_modules\webpack is outside your project directory.
    For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permble this preflight check in case you want to proceed anyway.

namikaz
  • 55
  • 8
1

One of the issue that you may face is the server won't start if some other server is running too . For eg. I had XAMP Running and thus my yarn couldn't start itself. Check it once.

1

This should work:

yarn add yarn
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
yusef7884
  • 37
  • 3
0

Updated the cache and all dependencies (yarn, node, npm), deleted the lock file - nothing helped. The issue was resolved simply by cloning the project to another directory. Apparently some kind of cache is tied to the directory and interferes with the build.

0

It doesn't open most likely because of older version of react, so you should use this code to upgrade react:

yarn upgrade --latest react-scripts

yarn start

0

yarn cache clean && yarn solved my problem.

West
  • 33
  • 4
-2

Reinstall yarn and run the function again. This worked for me.

Eshe
  • 1
-7

Try this:

1.Reinstall node.js

2.Reinstall VSC (if you use that)

3.Go to cmd and run:

  • npx create-react-app app-name
  • cd app-name
  • yarn start

4.Open your app at http://localhost:3000

5.Close cmd

6.Open VSC and run same command:

  • yarn start

and app is working! I hope that my solution will help someone.