gpt4 book ai didi

node.js - 尝试同时运行(npm ERR!代码 ELIFECYCLE npm ERR!)

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:42 28 4
gpt4 key购买 nike

我正在尝试创建一个从 API 获取数据的全栈 Node 和 Vue 应用程序。我遇到了一个问题,我试图同时运行客户端和服务器,但代码遇到错误。如果我错误地构建了这个问题,请耐心等待,因为我对编码还很陌生!

这是以下错误日志:

[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”脚本:

{
"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 命令时,程序运行良好,但是在安装客户端文件夹并添加客户端和开发脚本时,我遇到了错误。

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

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 提交,现在我陷入了困境。

我认为这个路由 .js 文件不是问题,但这里只是以防万一 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

关于node.js - 尝试同时运行(npm ERR!代码 ELIFECYCLE npm ERR!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59395339/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com