sst / ion

SST v3
https://sst.dev
MIT License
1.59k stars 203 forks source link

sst dev not reloading environments for frontends #1024

Open jayair opened 1 week ago

jayair commented 1 week ago

Say I have a Next.js app running locally through SOME_ENV_VAR=FOO sst dev.

new sst.aws.Nextjs("MyWeb", {
  environment: {
    SOME_ENV_VAR: process.env.SOME_ENV_VAR || "default",
  },
});
export default function Home() {
  return <p>Hello {process.env.SOME_ENV_VAR}</p>; // FOO
}

Now if I restart it with SOME_ENV_VAR=BAR sst dev , it doesn't update the env var.

export default function Home() {
  return <p>Hello {process.env.SOME_ENV_VAR}</p>; // still FOO
}

You need to restart sst dev again for it to take effect. Applies to resource links as well.

john20xdoe commented 1 week ago

Is this issue only for frontends? I see something similar that requires me to also manually restart sst dev, but for a NestJS API dist/ folder.

My ApiGatewayV2+Function (./infra/service.ts):

const functionArgs: FunctionArgs = {
  runtime: 'nodejs20.x', // fixes issue where al2023 is defaulted and a bootstrap binary is included in zip
  bundle: 'dist/apps/my-service',
  handler: 'main.handler',
  url: true,
  dev: false,
  // link: [templates, documents],
  copyFiles: [
    { from: 'dist/apps/my-service/main.js', to: 'main.js' },
  ],
};

export const api = new sst.aws.ApiGatewayV2('MyApi');
api.route('$default', functionArgs);

Notice it should deploy my dist folder (nested since this is a nestjs monorepo with an apps/ subfolder) by watching it for changes. dist is already autodeleted and rebuilt into commonjs format of main.js every time I used my nest build command. But, sst dev does not detect the changes to dist bundle. I had to manually restart it for it to redeploy.

Side Note: I'm not sure if (the dev: false) is related, but removing it makes my api respond with "it does not seem like sst dev is running" which is not true. Using dev: false makes it respond properly (firing at the endpoint URL from my local terminal curl command) .

thdxr commented 6 days ago

we likely have an issue with using bundle in dev mode

thdxr commented 6 days ago

can you make an other issue for that?

jayair commented 6 days ago

Tested this in Astro, saw the same thing.