在托管平台上运行“ npm start”时出错

时间:2019-06-01 18:41:13

标签: node.js reactjs express hosting

我在Express项目中有一个React应用。 Express项目的“ dev”脚本设置为启动Express项目和React应用程序。一切在本地都可以正常运行,但是当我上传所有内容时(我正在使用A2托管,并通过this article安装了node和npm)并运行dev脚本,它只是说这两个都在启动,但挂死了,从没有经过npm info lifecycle nrdesign@0.1.1~start: nrdesign~0.1.0。无论如何,我决定尝试运行React应用程序,因为我拥有Express项目的唯一原因是针对Nodemailer,并且它无法启动脚本,并打印了以下日志。我对日志一无所知,想知道是否能得到一些帮助。抱歉,长帖子:P。我将在下面添加index.js,package.json和日志。

文件夹结构:

Express
  |___app.js
  |___package.json (express)
  |___client
    |___index.js
    |___package.json (react)

Express app.js:

var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");

var indexRouter = require("./routes/index");

var app = express();

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "jade");

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use("/", indexRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get("env") === "development" ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render("error");
});

app.listen(40001);

module.exports = app;

反应index.js:

import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import "./animate.min.css";
import "./wing.css";
import App from "./App.js";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(<App />, document.getElementById("root"));
serviceWorker.unregister();

Express package.json:

{
  "name": "react-backend",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www",
    "dev": "(cd client && npm run start) && npm run start"
  },
  "dependencies": {
    "cookie-parser": "~1.4.4",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "http-errors": "~1.6.3",
    "jade": "~1.11.0",
    "morgan": "~1.9.1",
    "npm-run-all": "^4.1.5"
  }
}

反应package.json:

{
  "name": "nrdesign",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:40001",
  "dependencies": {
    "axios": "^0.19.0",
    "nodemailer": "^6.2.1",
    "react": "^16.8.6",
    "react-animated-css": "^1.2.1",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1"
  },
  "scripts": {
    "start": "PORT=40000 react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

在“客户端”文件夹日志中运行“ npm start”:

0 info it worked if it ends with ok
1 verbose cli [ '/home/nrdesign/bin/node', '/home/nrdesign/bin/npm', 'start' ]
2 info using npm@6.9.0
3 info using node@v10.16.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle nrdesign@0.1.0~prestart: nrdesign@0.1.0
6 info lifecycle nrdesign@0.1.0~start: nrdesign@0.1.0
7 verbose lifecycle nrdesign@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle nrdesign@0.1.0~start: PATH: /home/nrdesign/nodejs/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/nrdesign/public_html/client/node_modules/.bin:/home/nrdesign/perl5/bin:/usr/local/jdk/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/usr/local/bin:/usr/X11R6/bin:/home/nrdesign/.local/bin:/home/nrdesign/bin
9 verbose lifecycle nrdesign@0.1.0~start: CWD: /home/nrdesign/public_html/client
10 silly lifecycle nrdesign@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle nrdesign@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle nrdesign@0.1.0~start: Failed to exec start script
13 verbose stack Error: nrdesign@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/nrdesign/nodejs/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/home/nrdesign/nodejs/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid nrdesign@0.1.0
15 verbose cwd /home/nrdesign/public_html/client
16 verbose Linux 3.10.0-714.10.2.lve1.5.19.8.el7.x86_64
17 verbose argv "/home/nrdesign/bin/node" "/home/nrdesign/bin/npm" "start"
18 verbose node v10.16.0
19 verbose npm  v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error nrdesign@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the nrdesign@0.1.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 ]

0 个答案:

没有答案