错误命令失败,退出代码为1。当我尝试运行yarn时

时间:2019-03-24 12:10:17

标签: node.js yarnpkg

我正在学习reactjs-Node.js 我试图运行服务器,所以我安装了yarn,nodemon,express 但是当我尝试说出自己的话  错误命令失败,退出代码为1。

我的错误是

    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>

我的package.json是

{
    "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"
    }
}

及其我的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}`))

5 个答案:

答案 0 :(得分:2)

您需要做的很简单: 请按照以下步骤操作:

  1. rm -rf node_modules
  2. 清理纱线缓存
  3. 纱线
  4. 纱线开始

答案 1 :(得分:0)

您可能面临的问题之一是,如果其他服务器也正在运行,则服务器将无法启动。 例如。我运行了XAMP,因此我的纱线无法启动。检查一次。

答案 2 :(得分:0)

尝试一下:

1。重新安装node.js

2。重新安装VSC(如果使用的话)

3。转到cmd并运行:

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

4。通过http:// localhost:3000

打开您的应用

5.Close cmd

6。打开VSC并运行相同的命令:

  • yarn start

,应用正在运行!我希望我的解决方案能对某人有所帮助。

答案 3 :(得分:0)

我遇到了同样的错误,并通过

将其修复
  1. 删除yarn_lock.json
  2. 删除node_modules/
  3. sudo apt-get update && apt-get install --only-upgrade yarnsudo apt-get upgrade
  4. 然后重做yarn install文件夹中的yarn runyarn buildpackage.json

如果上面没有帮助

  1. 尝试安装最新的node.js
  2. 删除node_modules/lock文件
  3. 使用npm installnpm run-script

答案 4 :(得分:0)

这应该有效:

yarn add yarn