sst / sst

Build full-stack apps on your own infrastructure.
https://sst.dev
MIT License
21.72k stars 1.64k forks source link

Bug: `node_modules` not bundled with open next build when using npm monorepo/workspaces #3937

Open jacksors opened 1 week ago

jacksors commented 1 week ago

When deploying an opennext app that's inside of an npm monorepo using workspaces, a node_modules folder is not bundled in the open next server_functions folder as it is when building a nextjs app with open next outside of a monorepo (when there is a node_modules folder inside the nextjs root).

For instance, if we have a nextjs app located at applications/nextjs, and we run sst deploy from the monorepo root where the root package.json and sst.config.ts is located, the built app will not have any dependencies included and will not be able to run.

jayair commented 1 week ago

I haven't tried it recently but usually it only bundles that directory if you have dependencies in the nodejs.install. Do you have something like that? Can I see your sst config for the Next.js site?

jacksors commented 1 week ago

I'm not sure what you mean by in the nodejs.install, could you clarify? Like global packages? Here's my config:

import { vpc } from "./vpc";
import {
  betterAuthSecret,
  googleClientId,
  googleClientSecret,
  queueApiKey,
  WEB_URL,
} from "./secrets";
import { appDb } from "./app-db";
import { bullmqPrimary } from "./bullmq";
import { devEmail, email, emailTemplate } from "./messaging";

export const web = new sst.aws.Nextjs("Web", {
  vpc,
  path: "applications/web/",
  dev: {
    url: "http://localhost:3000",
  },
  link: [
    appDb,
    googleClientId,
    googleClientSecret,
    queueApiKey,
    betterAuthSecret,
    bullmqPrimary,
    emailTemplate,
    email ? email : [],
    devEmail ? devEmail : [],
  ],
  environment: { WEB_URL },
});

The workaround I'm currently using is just removing applications/web/ from my root package.json so the nextjs app's dependencies are handled separately from the rest of the monorepo's, but this breaks the automated deployment on the SST cosole since that only installs packages in the root directory.

Thanks for taking a look at this!

jayair commented 1 week ago

That looks okay to me. We'll need to test this out.