Vercel CLI built Preview works, but Production won't

Problem Definition

I have a NestJS app, that does static file serving. I have been using Vercel CLI to build and deploy.

When I build and deploy using those commands, it works perfectly fine:

vercel build
vercel deploy --prebuilt

Deployed Preview link: https://stardew-save-analyzer-3surl9ulc-igoodies-projects.vercel.app/


However, when I build for Production via those commands:

vercel build --prod
vercel deploy --prebuilt --prod

It fails with 500 “The Serverless Function has crashed”.
Deployed Production link: https://stardew-save-analyzer.vercel.app/

Logs From Production

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@nestjs/core' imported from /var/task/dist/server/index.mjs
    at packageResolve (node:internal/modules/esm/resolve:858:9)
    at moduleResolve (node:internal/modules/esm/resolve:931:18)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1173:14)
    at defaultResolve (node:internal/modules/esm/resolve:1216:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
    at link (node:internal/modules/esm/module_job:95:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@nestjs/core' imported from /var/task/dist/server/index.mjs
    at packageResolve (node:internal/modules/esm/resolve:858:9)
    at moduleResolve (node:internal/modules/esm/resolve:931:18)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:1173:14)
    at defaultResolve (node:internal/modules/esm/resolve:1216:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:542:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
    at link (node:internal/modules/esm/module_job:95:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.

I wonder how is this not the case with the Preview build, but crashes with a simple package not found issue in Production. I appreciate any help or insight that I might be missing in advance!

Project Information

It is an Open Source Project, you can check out the code: GitHub - CoconutGoodie/stardew-save-analyzer: 🌿 Save Analyzer & Tracker for Stardew Valley the Game
It uses Vike with NestJS backend, which serves static frontend files.

Have you tried to adjust your project’s Build & Development Settings and try to deploy it using vercel deploy --prod (without the --prebuilt flag)? So the project is built on Vercel’s servers. At least the output of the build there could help you to debug your issue further.

1 Like

Yes I also tried deploying with:

vercel deploy --prod

Unfortunately the output is the same. Serverless Function crashes with the same log

What CLI version are you using?

If it’s not already updated to the latest version (currently 39.3.0), please run npm i -g vercel@latest to update it and try the production deployment again with that version :pray:

1 Like

I am using v39.3.0 already :frowning_face:

image

Thanks for confirming that. I took a look through the repo and noticed that the vercel.json has builds and routes configured for the dist/server/index.mjs path. That setup could be the cause of the missing package error.

There are a few articles written about how to deploy a NestJS app with Vercel. I find How to deploy your NestJS apps on Vercel - DEV Community and Deploying a NestJS Application on Vercel with a PostgreSQL Database - DEV Community particularly helpful. I recommend following their project setup.

If you give that a try, please let us know how it goes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.