尝试并发运行(npm ERR!代码 ELIFECYCLE npm ERR!) [英] Trying to run concurrently (npm ERR! code ELIFECYCLE npm ERR!)

查看:64
本文介绍了尝试并发运行(npm ERR!代码 ELIFECYCLE npm ERR!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个全栈节点 &从 API 获取数据的 Vue 应用程序.我遇到了一个问题,我试图同时运行客户端和服务器,但代码遇到错误.如果我对这个问题的结构有误,请多多包涵,因为我对编码还很陌生!

I am trying to create a Full Stack Node & Vue application that takes data from an API. I am running into an issue where I am trying to run both the client and server concurrently but the code is running into an error. Please bear with me if I am structuring this question wrong as I am still fairly new to coding!

这是以下错误日志:

[0] Error occurred when executing command: npm run server
[0] Error: spawn cmd.exe ENOENT
[0]     at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[0]     at onErrorNT (internal/child_process.js:469:16)
[0]     at processTicksAndRejections (internal/process/task_queues.js:84:21)     
[1] Error occurred when executing command: npm run client
[1] Error: spawn cmd.exe ENOENT
[1]     at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[1]     at onErrorNT (internal/child_process.js:469:16)
[1]     at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] npm run client exited with code -4058
[0] npm run server exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! apex-tracker@1.0.0 dev: `concurrently "npm run server" "npm run client"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the apex-tracker@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

据我所知,程序运行良好,直到它到达我的 package.json 中的dev"脚本:

From what I can tell the program is running fine up until it reaches the "dev" script in my package.json:

{
  "name": "apex-tracker",
  "version": "1.0.0",
  "description": "Apex Legends user statistics tracker",
  "main": "server.js",
  "scripts": {
    "start": "node server",
    "server": "nodemon server",
    "client": "npm run serve --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "author": "Jared Mackay",
  "license": "MIT",
  "dependencies": {
    "concurrently": "^5.0.1",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "morgan": "^1.9.1",
    "node-fetch": "^2.6.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.2"
  }
}

在出现错误之前,当我运行 npm run server command 时程序运行良好,但是在安装客户端文件夹并添加客户端和开发脚本时,我遇到了错误.

prior to the errors, the program ran fine when I ran the npm run server command, however upon installing the client folder and adding the client and dev script that's when I ran into my errors.

这是我试图与客户端一起运行的 server.js:

Here is my server.js that I am trying to run with the client:

const express = require('express');
const morgan = require('morgan');
const dotenv = require('dotenv');

//Load configuration file
dotenv.config({ path: './config.env' })

const app = express();

//Develper logging
if (process.env.NODE_ENV === 'development') {
    app.use(morgan('dev'));
}

//Profile routes
app.use('/api/v1/profile', require('./routes/profile'));

const port=process.env.PORT || 8000;

app.listen(port, () => {
    console.log(`Server running on ${process.env.NODE_ENV} mode on port ${port}`);
});

我尝试清除 npm 缓存,删除并重新安装 node-modules 以及 package-lock.json,但这产生了更多问题而不是修复它们.我不得不恢复到旧的 git 提交,现在我卡住了.

I've tried clearing the npm cache, deleting and reinstalling node-modules as well as package-lock.json, but this created more issues rather than fixing them. I had to revert back to an old git commit and now I'm stuck.

我不认为这个路由 .js 文件是一个问题,但这里只是为了防止 profile.js:

I don't think this route .js file is an issue but here it is just in case profile.js:

const express = require('express');
const router = express.Router();
const fetch = require('node-fetch');

router.get('/:platform/:gamertag', async (req, res) => {
    try {
        const headers  = {
            'TRN-Api-Key': process.env.TRACKER_API_KEY
        }

        const { platform, gamertag } = req.params;

        const response = await fetch(
            `${process.env.TRACKER_API_URL}/profile/${platform}/${gamertag}`, 
            {
                headers
            }
        );

        const data = await response.json();

        if(data.errors && data.errors.length > 0) {
            return res.status(404).json({
                message: 'Profile Not Found'
            });

        }

        res.json(data);
    }   catch (err) {
        console.error(err);
        res.status(500).json({
            message: 'Server Error'
        });
    }
});

module.exports = router;

先谢谢你!

推荐答案

spawn cmd.exe ENOENT

您的程序不知道在哪里可以找到 cmd.exe.

Your program does not know where to find cmd.exe.

这篇关于尝试并发运行(npm ERR!代码 ELIFECYCLE npm ERR!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆