最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Error building react build folder using vercel.json. Attempting to build react build folder as well as run serverless

programmeradmin0浏览0评论

Project background:

  • I have a fullstack project with 2 subfolders: client(reactJS) and server(nodeJS).
  • Using vercel to deploy the entire fullstack project
  • Folder anisation:
- client
    - src
      - index.js
      - App.js
      - components... etc
    - package.json
- server
    - index.js #contains express and mongodb config
    - server.js #starting point of routes
    - package.json
- vercel.json
  • How files are planned to be served:
    • First run cd client && npm run build
    • then run cd server && node index.js (the static files will be served via the backed from client/build folder)

Problem:

I wanted to first build the client using vercel and then serve the serevr using vercel. The issue is occuring during the build. In vercel.json I have set up the following:

{
  "version": 2,
  "builds": [
    {
      "src": "client/package.json",
      "use": "@vercel/static-build"
    },
    {
      "src": "server/package.json",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/.*",
      "dest": "server/src/server.js"
    }
  ]
}

According to this (as I understood from vercel logs) first the client needs to be built according to the build command in client/package.json:

{
  "name": "ebazar-client",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start": "react-scripts start",
    "build": "npm install --legacy-peer-deps && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:8080",
  "homepage": "/",
  "dependencies": {
    "@emotion/react": "^11.13.3",
    "@emotion/styled": "^11.13.0",
    "@headlessui/react": "^1.7.18",
    "@heroicons/react": "^1.0.6",
    "@material-ui/core": "^4.12.4",
   .
   .
   etc

and then the server needs to be built and served according to the script in server/package.json:

{
  "name": "ebazar-server",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "dev": "nodemon --trace-warnings src/index",
    "build": "npm i && cd ../client && npm run build",
    "start": "node src/index",
    "test": "cross-env NODE_ENV=test jest --runInBand --detectOpenHandles",
    "test:coverage": "cross-env NODE_ENV=test jest --coverage --runInBand --detectOpenHandles"
  },
   .
   .
   etc

I know my server scripts may have errors, but currently I'm trying to debug the issues related to the scripts in client/package.json. When I run vercel via cli the below error occurs:

$ vercel
Vercel CLI 40.1.0
发布评论

评论列表(0)

  1. 暂无评论