Trying to run concurrently (npm ERR! code ELIFECYCLE npm ERR!)

僤鯓⒐⒋嵵緔 提交于 2021-02-10 18:30:31

问题


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!

This is the following error log:

[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.

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

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.

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}`);
});

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.

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;

Thank you in advance!


回答1:


spawn cmd.exe ENOENT

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



来源:https://stackoverflow.com/questions/59395339/trying-to-run-concurrently-npm-err-code-elifecycle-npm-err

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!