Michael
Michael

Reputation: 439

Serverless Function Invocation Failed nestjs vercel

I'm facing some issue when trying to deploy my nest js app to vercel.

(It's working only locally on my machine when I running npm run start:dev )

I've created vercel.json file with next values:

{
  "version": 2,
  "builds": [
    {
      "src": "src/main.ts",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "src/main.ts",
      "methods": [
        "GET",
        "POST",
        "PUT",
        "DELETE"
      ]
    }
  ]
}

After that I added it to vercel and deployed. When I trying to access the url I get next error:

[32m[Nest] 8  - [39m03/16/2023, 3:08:07 PM [32m    LOG[39m [38;5;3m[NestFactory] [39m[32mStarting Nest application...[39m
[32m[Nest] 8  - [39m03/16/2023, 3:08:07 PM [32m    LOG[39m [38;5;3m[InstanceLoader] [39m[32mMongooseModule dependencies initialized[39m[38;5;3m +77ms[39m
[32m[Nest] 8  - [39m03/16/2023, 3:08:07 PM [32m    LOG[39m [38;5;3m[InstanceLoader] [39m[32mJwtModule dependencies initialized[39m[38;5;3m +1ms[39m
[32m[Nest] 8  - [39m03/16/2023, 3:08:07 PM [32m    LOG[39m [38;5;3m[InstanceLoader] [39m[32mAppModule dependencies initialized[39m[38;5;3m +0ms[39m
No exports found in module "../src/main.js".
Did you forget to export a function or a server?
RequestId: 189f268e-5a0d-4099-965a-e96324d2ec23 Error: Runtime exited with error: exit status 1
Runtime.ExitError

Upvotes: 2

Views: 1514

Answers (2)

wahyu nanda
wahyu nanda

Reputation: 406

you can change it to like this and redeploy

{
    "version": 2,
    "builds": [
        {
            "src": "src/main.ts",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "src/main.ts",
            "methods": [
                "GET",
                "POST",
                "PUT",
                "PATCH",
                "OPTIONS",
                "DELETE",
                "HEAD",
                "CONNECT",
                "TRACE"
            ]
        }
    ]
}

Upvotes: 0

Nicolas Alvarez
Nicolas Alvarez

Reputation: 1

I had the same issue minutes before, just updating package.json with

"type": "commonjs"

worked for me!

Upvotes: -1

Related Questions