【问题标题】:error Command failed with exit code 1. when I try to run yarn错误命令失败,退出代码为 1。当我尝试运行纱线时
【发布时间】:2019-03-24 12:10:17
【问题描述】:

我正在学习 reactjs - nodejs 我试图运行服务器,所以我安装了 yarn、nodemon、express 但是当我尝试运行它的说法时 error 命令失败,退出代码为 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}`))

【问题讨论】:

  • 您可以通过将"private": true 添加到package.json 来修复“无许可证字段”警告。

标签: node.js yarnpkg


【解决方案1】:

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

  1. rm -rf 节点模块
  2. 纱线缓存清理
  3. 纱线
  4. 纱线开始

【讨论】:

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

我遇到了同样的错误,我按照以下步骤修复了它:

  1. 删除yarn_lock.jsonrm -rf yarn_lock.json(如果您是Linux/MacOS 用户)
  2. 删除node_modules/rm -rf node_modules/(如果您是Linux/MacOS 用户)
  3. 按照说明安装来自here 的最新 Yarn 包
  4. 尝试在项目根文件夹中执行以下命令:

yarn installyarn start

如果上述方法没有帮助:

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

【讨论】:

    【解决方案3】:

    这应该可行:

    yarn add yarn
    

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

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

        $ yarn info 
        $ yarn upgrade 
        $ yarn add yarn 
        

        如果显示更多错误,请运行:

        export NODE_OPTIONS=--openssl-legacy-provider
        

        完成

        【讨论】:

          【解决方案6】:

          要修复依赖关系树,请尝试按照以下步骤进行操作:

          1. 删除项目文件夹中的 package-lock.json(不是 package.json!)和/或 yarn.lock。
          2. 删除项目文件夹中的 node_modules。
          3. 从项目文件夹的 package.json 文件中的依赖项和/或 devDependencies 中删除“webpack”。
          4. 运行 npm install 或 yarn,具体取决于您使用的包管理器。

          在大多数情况下,这应该足以解决问题。 如果这没有帮助,您可以尝试其他一些方法:

          1. 如果您使用 npm,请安装 yarn (http://yarnpkg.com/) 并使用它重复上述步骤。 这可能会有所帮助,因为 npm 已经知道包提升的问题,这些问题可能会在未来的版本中得到解决。

          2. 检查 C:\Users\nouss\OneDrive\Images\SocialM\react-social\node_modules\webpack 是否在您的项目目录之外。
            例如,您可能不小心在主文件夹中安装了一些东西。

          3. 尝试在您的项目文件夹中运行 npm ls webpack。 这将告诉您安装了 webpack 的其他包(除了预期的 react-scripts)。

          如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 如果您仍然想继续进行,这将允许此预检检查。

          【讨论】:

            【解决方案7】:

            更新了缓存和所有依赖项(yarn、node、npm),删除了锁定文件——没有任何帮助。 只需将项目克隆到另一个目录即可解决问题。显然,某种缓存与目录相关联并干扰了构建。

            【讨论】:

              【解决方案8】:

              试试这个:

              1.重新安装node.js

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

              3.进入cmd运行:

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

              4.在 http://localhost:3000 打开你的应用

              5.关闭cmd

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

              • yarn start

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

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2021-10-08
                • 2017-04-20
                • 2018-07-12
                • 2015-10-12
                • 2021-09-15
                • 2018-10-15
                • 1970-01-01
                相关资源
                最近更新 更多