error Command failed with exit code 1. when I try to run yarn
Asked Answered
A

13

50

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}`))
Argilliferous answered 24/3, 2019 at 12:10 Comment(1)
You can fix the "no license field" warning by adding "private": true to the package.json.Parry
N
65

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
Nightdress answered 7/4, 2020 at 5:6 Comment(4)
Just wondering if there's any explanation behind that? ThanksJoplin
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.Tailpipe
after all 4 steps I got the same error. How can I fix it?Bassorilievo
"Have you tried to turn it off and on again?" --> Why is literally 50%+ of all those yarn problems more or less the same...Troyes
P
9

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
Pinard answered 22/9, 2020 at 10:24 Comment(0)
S
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

Stoush answered 1/12, 2021 at 18:11 Comment(0)
L
3

This should work:

yarn add yarn
Lack answered 15/10, 2020 at 8:55 Comment(0)
K
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.

Kipp answered 13/3, 2022 at 8:19 Comment(0)
A
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.

Allot answered 15/3, 2020 at 15:8 Comment(0)
J
1

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.

Juniorjuniority answered 12/10, 2021 at 7:55 Comment(0)
L
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

Lollapalooza answered 20/6, 2022 at 11:26 Comment(0)
G
0

yarn cache clean && yarn solved my problem.

Gasconade answered 24/7, 2023 at 7:38 Comment(0)
G
0

This worked for me:

rm -rf node_modules
yarn cache clean
yarn

And if deleting the directory modules gives an error of permissions, just go to the directory and it works!

Then run the project

Gramarye answered 25/6, 2024 at 21:46 Comment(0)
S
-2

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

Stearn answered 8/5, 2022 at 5:24 Comment(0)
S
-2

maybe you can try:sudo yarn :)

if you are using node v20, pls run: nvm use 16.20.2 to degrade the node version (btw it works on your current terminal, pls note)

use nvm ls to check the all version of node you have installed.

Skipper answered 25/11, 2023 at 23:45 Comment(0)
J
-8

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.

Jolson answered 24/8, 2020 at 20:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.