sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 126 forks source link

'Runtime.HandlerNotFound' when accessing deployed site #444

Closed Jhinger closed 1 month ago

Jhinger commented 1 month ago

Currently trying to deploy a barebones SolidStart app in ion - the build itself is successful and I can preview the app by running node ./output/server/index.mjs or sst dev npm run dev, however when I try to access the app at the cloudfront url I get error code 502 and I see the following error in console.sst:

Uncaught Exception  {
  "errorType": "Runtime.HandlerNotFound",
  "errorMessage": ".output/server/index.handler is undefined or not exported",
  "stack": [
    "Runtime.HandlerNotFound: .output/server/index.handler is undefined or not exported",
    "    at UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1122:15)",
    "    at async start (file:///var/runtime/index.mjs:1282:23)",
    "    at async file:///var/runtime/index.mjs:1288:1"
  ]
}

Here is my sst.config:

import * as aws from "@pulumi/aws";

export default $config({
  app(input) {
    return {
      name: "rmc",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
    };
  },
  async run() {
    const db = new aws.rds.Instance("Database", {
      instanceClass: "db.t4g.micro",
      allocatedStorage: 20,
      dbName: "rmcdb",
      engine: "postgres",
      username: "",
      password: "",
      skipFinalSnapshot: true,
      identifierPrefix: "rmc",
    })
    new sst.aws.SolidStart("RMC", {
      link: [db]
    })

    return {
      app: $app.name,
      db: db.dbName,
      stage: $app.stage,
    }
  },
});

Any help on resolving this would be appreciated.

jayair commented 1 month ago

If you compare the version of your dependencies to the one in the quick start, are they similar? https://github.com/sst/ion/tree/dev/examples/aws-solid-start

Jhinger commented 1 month ago

Yeah - everything is the same

  "dependencies": {
    "@aws-sdk/client-rds-data": "^3.577.0",
    "@pulumi/aws": "^6.36.0",
    "@solidjs/router": "^0.13.3",
    "@solidjs/start": "^1.0.0-rc.0",
    "autoprefixer": "^10.4.19",
    "drizzle-kit": "^0.21.2",
    "drizzle-orm": "^0.29.5",
    "postcss": "^8.4.38",
    "solid-js": "^1.8.17",
    "sst": "ion",
    "tailwindcss": "^3.4.3",
    "vinxi": "^0.3.11"
  },
  "engines": {
    "node": ">=18"
  },
  "devDependencies": {
    "@types/aws-lambda": "8.10.138"
  },
  "overrides": {
    "nitropack": "npm:nitropack-nightly@latest"
  }
Jhinger commented 1 month ago

I tried this again following the minimal SolidStart example, and I'm still seeing the same issue when deploying the app so it has to be something on my end - but I'm not exactly sure what.

Edit: Deploying an Astro site works fine - I can see an exported handler in entry.js in the lambda function for the Astro site, however for the Solid app I cannot find any exported handler in index.js so this might be a Solid/nitro specific issue?

thdxr commented 1 month ago

what package manager are you using? we have to force use of the nightly of nitropack and it's possible your package manager is not resolving it properly

Jhinger commented 1 month ago

I'm using npm - I also tried with Bun however and got the same result.

Jhinger commented 1 month ago

Ah, found my issue - I didn't have any value set for server.preset in app.config.ts 😐. Updating the value to aws-lambda resolved the issue.

import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
  server: {
    preset: "aws-lambda"
  },
  vite: {
    resolve: {
      alias: {
        "@": "/src"
      }
    },
  }
});