【问题标题】:Node.js API Server - Unable to buildNode.js API 服务器 - 无法构建
【发布时间】:2020-06-15 18:20:03
【问题描述】:

我在创建 Node Js API 应用程序的构建时遇到了困难。

下面是我的 package.json 文件的样子:

{
    "name": "node-mongo-registration-login-api",
    "version": "1.0.0",
    "description": "NodeJS + MongoDB API for User Management, Authentication and Registration",
    "main": "server.js",
    "license": "MIT",
    "scripts": {
        "start": "node ./server.js",
        "start-dev": "nodemon ./server.js",
        "build": "react-scripts build"
    },
    "dependencies": {
        "bcryptjs": "^2.4.3",
        "body-parser": "^1.19.0",
        "cors": "^2.8.5",
        "express": "^4.17.1",
        "express-jwt": "^5.3.3",
        "jsonwebtoken": "^8.5.1",
        "mongodb": "^3.5.6",
        "mongoose": "^5.9.10",
        "react-scripts": "^3.4.1",
        "rootpath": "^0.1.2"
    },
    "devDependencies": {
        "nodemon": "^2.0.3"
    }
}

当我运行 npm run build 时,出现以下错误:

Could not find a required file.
  Name: index.html
  Searched in: C:\Users\Tejas\Desktop\React\Templates\node-mongo-registration-login-api-master\public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-mongo-registration-login-api@1.0.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-mongo-registration-login-api@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Tejas\AppData\Roaming\npm-cache\_logs\2020-06-15T10_12_13_343Z-debug.log

我不确定为什么在不需要 UI 的服务器应用程序中需要 index.html。

【问题讨论】:

    标签: node.js npm nodemon


    【解决方案1】:

    如果您只是实现 API 而没有 React 应用程序,则不需要构建它。使用npm run start 启动您的服务器。

    【讨论】:

    • 我需要将它部署到 heroku,当我推送它时也会出现此错误
    • 我猜你已经将npm run build 定义为你在heroku 中的启动脚本。此命令运行您的构建脚本,该脚本是在您的包 json 中定义的 react-scripts build。你不需要它,因为你没有反应应用程序。最好将您的heroku启动脚本更改为npm run start,或者您可以将包json中的构建脚本更改为:"build": "npm run start"
    • 谢谢。我刚刚删除了构建线,它工作正常!
    猜你喜欢
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2020-01-18
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    相关资源
    最近更新 更多