2

I have the following scripts in my package.json

"scripts": {
    "dev": "nodemon --exec babel-node src/index.js",
    "build": "NODE_ENV=PRODUCTION babel src -d dist --copy-files",
    "serve": "NODE_ENV=production node dist/index.js"
  },

My application builds, but only the dist/index.js is just served up as a file rather than being run.

I have tried to change serve to start but no luck.

Have also tried to run the serve script as part of the build with && - this yielded a build process that just runs.

I feel like the solution is trivial, and I am just making mistake with my scripts.

Any ideas?

Ben S
  • 558
  • 3
  • 18

2 Answers2

0

Vercel is a static-first platform. You can't lift a server inside the platform and for that reason, it is not possible to use a classic "listen" approach.

Take a look at vercel.com/new and also a few examples.

paulogdm
  • 1,572
  • 14
  • 20
  • 1
    next.js with server render is working well and it is not statis. why they removed documentation about now.json like { "version": 2, "builds": [{ "src": "index.js", "use": "@now/node-server" }], } – Alex Kapelyukhovskiy May 20 '20 at 14:16
0

I would suggest you either you leverage the vercel serverless functions config, or you set it up the old way, using a vercel.json file that contains:

once you deploy your code to vercel, you need to :

{
  "version": 2,
  "builds": [
    {
      "src": "dist/index.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "dist/index.js"
    }
  ]
}

Since you are using the builds vercel.json option, you need to ensure all the dependencies, like the compiled dist folder and the node_modules are uploaded.

Alberto S.
  • 1,805
  • 23
  • 39
  • I have tried both previously, none worked well, due to lack of documentation. I ended up opting for Netlify and proper lambdas. – Ben S Mar 18 '21 at 17:12
  • Are you using the "builds" definition on vercel.json? Have you verify that the "dist" files are uploaded to vercel ( use the vercel file explorer to verify ). This is the approach that is working for me right now, on a node express app, done in typescript – Alberto S. Mar 20 '21 at 07:55