«npm start» выдает ошибку, в то время как «узел main. js» - нет (express) - PullRequest
0 голосов
/ 01 марта 2020

Итак, я делаю приложение для узлов, и оно прекрасно работает, когда я запускаю его, набирая node main.js, но когда я запускаю npm start, выдается ошибка:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v12.16.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle osadnicy-serwer@1.0.0~prestart: osadnicy-serwer@1.0.0
6 info lifecycle osadnicy-serwer@1.0.0~start: osadnicy-serwer@1.0.0
7 verbose lifecycle osadnicy-serwer@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle osadnicy-serwer@1.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\HTML\JavaScript\osadnicy-serwer\node_modules\.bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\EgisTec MyWinLocker\x64;C:\Program Files (x86)\EgisTec MyWinLocker\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;;C:\Users\zdzisława\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\zdzisława\AppData\Roaming\npm;C:\Program Files\heroku\bin
9 verbose lifecycle osadnicy-serwer@1.0.0~start: CWD: C:\HTML\JavaScript\osadnicy-serwer
10 silly lifecycle osadnicy-serwer@1.0.0~start: Args: [ '/d /s /c', 'node main.js' ]
11 silly lifecycle osadnicy-serwer@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle osadnicy-serwer@1.0.0~start: Failed to exec start script
13 verbose stack Error: osadnicy-serwer@1.0.0 start: `node main.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:321:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:321:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid osadnicy-serwer@1.0.0
15 verbose cwd C:\HTML\JavaScript\osadnicy-serwer
16 verbose Windows_NT 6.1.7601
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.16.0
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error osadnicy-serwer@1.0.0 start: `node main.js`
22 error Exit status 1
23 error Failed at the osadnicy-serwer@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

и вот package. json file:

{
  "name": "osadnicy-serwer",
  "config": {
    "port": "3000"
  },
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node main.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "circular-json": "file:circular-json",
    "express": "^4.17.1",
    "socket.io": "^2.3.0"
  },
  "engines": {
    "node": "12.16.0"
  }
}

и main. js:

const express = require("express");
const path = require("path");
const fs = require("fs");
const app = express();
const http = require("http").createServer(app);
global.io = require("socket.io")(http);
const Board = require("./Board").Board;
const Player = require("./Player").Player;
const Market = require("./Market").Market;
const Progress = require("./Progress").Progress;
const Interface = require("./Interface").Interface;
const CircularJSON = require("circular-json");
const port = 3000;
global.market = new Market();
global.board = new Board(3, 50);
board.pushNubers();
board.createHexes();
board.createPorts();
global.hexRadius = 50;
global.currentLongestRoad = { playerIndex: null, number: 4 };
global.currentHighestKnightPower = { playerIndex: null, number: 2 };
global.players = [new Player("red"), new Player("beige")];
global.currentRound = 1;
global.diceResult = 0;
global.activePlayerIndex = 0;
global.progress = new Progress();
global.currentPlayer = players[activePlayerIndex];
const interface = new Interface(currentPlayer, board);
let move = {};
// app.configure(function() {
//   app.use(app.router);
// });
app.use(express.json({ limit: "5mb" }));
app.use(express.static("client"));
// app.use(bodyParser.json());

fs.writeFileSync("./JSON/board.json", JSON.stringify(board));
fs.writeFileSync("./JSON/players.json", JSON.stringify({ players }));
fs.writeFileSync("./JSON/market.json", JSON.stringify(market));
fs.writeFileSync("./JSON/move.json", "");

app.get("/", (req, res) => {
  res.sendFile(path.join(__dirname, "client", "client.html"));
});
app.get("/board", (req, res) => {
  res.send(CircularJSON.stringify(board));
});
app.put("/card", (req, res) => {
  progress.handleCardPlay(req.body.card, req.body.i);
  res.send("ok");
});
app.get("/monopoly/:i", (req, res) => {
  progress.handleMonopoly(req, params.i);
  res.send("ok");
});
app.get("/invention/:i"),
  (req, res) => {
    progress.handleInvention(req.params.i);
    res.send("ok");
  };
app.put("/progress", (req, res) => {
  players[req.body.playerIndex].progressCards.push({
    type: progress.generateCard(),
    age: currentRound
  });
  players[req.body.playerIndex].resources[1] -= 1;
  players[req.body.playerIndex].resources[3] -= 1;
  players[req.body.playerIndex].resources[4] -= 1;
  io.emit("resources updated");
  res.send(
    JSON.stringify({
      progressCards: players[req.body.playerIndex].progressCards
    })
  );
});
app.get("/move", (req, res) => {
  res.sendFile(path.join(__dirname, "JSON", "move.json"));
});
app.get("/players", (req, res) => {
  res.send(CircularJSON.stringify({ players }));
});
app.get("/globals", (req, res) => {
  res.send(
    CircularJSON.stringify({
      currentRound,
      diceResult,
      activePlayerIndex,
      currentHighestKnightPower,
      currentLongestRoad
    })
  );
});
app.put("/globals", (req, res) => {
  if (req.body.currentRound === 2) {
    players[req.body.activePlayerIndex].freeSettlement = true;
    players[req.body.activePlayerIndex].freeRoads = 1;
  }
  currentRound = req.body.currentRound;
  diceResult = req.body.diceResult;
  activePlayerIndex = req.body.activePlayerIndex;
  currentHighestKnightPower = req.body.currentHighestKnightPower;
  currentLongestRoad = req.body.currentLongestRoad;
  res.send("globals updated");
  io.emit("globals updated");
  board.hexes.forEach(hex => hex.payResources());
  fs.writeFileSync("./JSON/globals.json", JSON.stringify(req.body));
  if (diceResult === 7) {
    board.thief.isSet = false;
  }
});
app.put("/thief", (req, res) => {
  board.thief.handleStealing(req.body.steal);
  res.send("ok");
  io.emit("resources updated");
});
app.get("/currentPlayer", (req, res) => {
  const currentPlayerIndex = players.findIndex(
    player => player === currentPlayer
  );
  res.send(JSON.stringify({ currentPlayerIndex }));
});
app.put("/market", (req, res) => {
  market.active = req.body.active;
  market.offer = req.body.offer;
  market.demands = req.body.demands;
  market.isOfferSet = req.body.isOfferSet;
  market.tradingPlayerIndex = req.body.tradingPlayerIndex;
  market.activePlayerIndex = req.body.activePlayerIndex;
  market.deal = req.body.deal;
  market.dealWith = req.body.dealWith;
  res.send("ok");
  io.emit("market updated");
  if (market.deal && market.dealWith === "otherPlayer") {
    market.handleTrade();
    market.closePopup();
    io.emit("current player updated");
    io.emit("resources updated");
  }
  if (market.deal && market.dealWith === "bank") {
    market.handleExchange();
    market.closePopup();
    io.emit("resources updated");
  }
});
app.get("/resources/:index", (req, res) => {
  res.send(JSON.stringify({ resources: players[req.params.index].resources }));
});
app.get("/progress/:index", (req, res) => {
  res.send(
    JSON.stringify({ progressCards: players[req.params.index].progressCards })
  );
});
app.get("/market", (req, res) => {
  res.send(JSON.stringify(market));
});
app.post("/move", (req, res) => {
  fs.writeFileSync("./JSON/move.json", JSON.stringify(req.body));
  move = req.body;
  res.send("move saved");
  io.emit("new move", move);
  interface.player = players[move.playerIndex];
  switch (move.type) {
    case "settlement build":
      interface.handleSettlementBuild(move.meeple);
      io.emit("resources updated");
      break;
    case "road build":
      interface.handleRoadBuild(move.meeple);
      io.emit("resources updated");
      break;
    case "thief setting":
      board.thief.isSet = true;
      board.thief.x = move.thiefHex.x;
      board.thief.y = move.thiefHex.y;
      break;
    case "city build":
      interface.handleCityBuild(move.meeple);
      io.emit("resources updated");
      break;
  }
});

http.listen(port, "0.0.0.0", () => {
  console.log("server is listening at port 3000");
});

Я не понимаю, почему бы просто не запустить ту же команду, было бы благодарен за любую помощь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...