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

hwi*_*iba 16 node.js yarnpkg

我正在学习 reactjs - nodejs 我试图运行服务器,所以我安装了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>
Run Code Online (Sandbox Code Playgroud)

我的 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"
    }
}
Run Code Online (Sandbox Code Playgroud)

它是我的 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}`))
Run Code Online (Sandbox Code Playgroud)

Sha*_*ala 10

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

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

  • 只是想知道这背后是否有任何解释?谢谢 (3认同)
  • 基本上可能存在错误获取依赖项或传输过程中发生某些情况的问题。Shailesh 建议您删除获取的依赖项,清理纱线缓存(有时可能是它)并从头开始获取依赖项。 (2认同)
  • 经过所有 4 个步骤后,我遇到了同样的错误。我该如何修复它? (2认同)

Kar*_*yan 8

我遇到了同样的错误,并通过以下步骤修复了它:

  1. 删除yarn.lockrm -rf yarn.lock(如果您是 Linux/MacOS 用户)
  2. 删除node_modules/rm -rf node_modules/ (如果您是 Linux/MacOS 用户)
  3. 按照说明安装此处提供的最新 Yarn 包
  4. 尝试在项目根文件夹中执行以下命令:

yarn installyarn start

如果上述方法没有帮助:

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


Byu*_*usa 7

这对我有用,(更新纱线)

$ yarn info 
$ yarn upgrade 
$ yarn add yarn 
Run Code Online (Sandbox Code Playgroud)

如果显示更多错误,请运行以下命令:

export NODE_OPTIONS=--openssl-legacy-provider
Run Code Online (Sandbox Code Playgroud)

完毕


小智 1

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