Is there something that …

3 minute read

Is there something that I’m missing? Is there no way to deploy each app separately?

Responses:

It depends on the framework, Using webpack might be the solution to bundle your dependency

This is just a next app that uses styled-components for styling. Should I be overriding the build that comes with this <https://nx.dev/react/plugins/next/builders/build plugin>?

Hmm not sure never used next before sorry I can’t be more help

No worries, thank you

Np, Someone around here should be able to point you in the right direction!

There was this issue recently about copying the public folder into the build output. They also mentioned the dependency matter but people didn’t agree whether you should need more dependencies than that during runtime (which you might, depending on your setup), but the ultimate result was to discuss it in a separate issue. I don’t know if that separate issue has been created yet but it’s definitely functionality that is missing right now.

https://github.com/nrwl/nx/issues/3019

Where are you deploying your next app ?

I’m just testing out nx. I’d like the ability to be able to individually deploy each app. For example, be able to deploy a Next app to Heroku. It looks like the generated package.json does not include the dependencies that my Next app has. It’s as though when building the Next app, the dependency packages are the default ones that come with Next, not any additional installed packages like styled-components, dates-fn, ramda, etc

That is definitely the intended behaviour, deploying each app individually I mean.

I believe the people that set up the original script just didn’t have a lot of nextjs experience themselves.

They assumed other dependencies would be bundled on build time, but that’s not really how next.js operates.

Yeah, it looks like one of the comments in the issue is spot on: +1 for both points you've raised. There's no much point of an automatically generated package.json if it doesn't contain all the dependencies of the project that's been built. Ideally, a vendor chunk should be generated so then all it's required is to just start next and not install anything else. Especially useful for artifact deployment.

Exactly :slightly_smiling_face:

So I’d say it’s a bug

I don’t think there is an issue for this yet, I’ll create one now

Right now I’m just copying the package.json from the root in my deploy script, “fixing” this problem manually after build time

Do you manually adjust the package.json? For instance, if I include a separate API app that has completely different dependencies. I wouldn’t want to install all the dependencies that all the apps may have in the workspace.

Nope, that’s the big downside of this “fix”

I’m using docker for the deployments so my Dockerfile looks like this right now:

```FROM node:12

WORKDIR /usr/app

COPY dist/apps/APPNAME /usr/app/.next

RUN yarn –production –pure-lockfile

COPY apps/APPNAME/public /usr/app/public

CMD yarn run next start -p $PORT```

I only have a couple of apps at the moment though, and they are both next.js based so it’s not a big concern for me for now, but I will be adding a few node apps which will cause this to be a problem for me

Ideally NX could figure out which packages are imported and listed as production dependencies and output that list in the resulting package.json

I honestly have no idea if it’s possible right now, but that would be the dream solution.

Same here! Is there a way to bump a feature up in priority list? lol

Haha exactly. Although a temporary alternative, albeit annoying, solution, would be to keep a separate package.json with the production dependencies for each app and just copy that package.json instead of the other one they generate

Downside is you have to maintain this extra package.json manually

Upside is you only include whatever you want to include

But ideally we’ll get this solution in

We actually populate the package.json for publishable libraries. We could do the same thing for apps. I wonder why we skipped this :thinking_face:

Oh no I remember, apps usually bundle everything in. This is probably just something next does differently

Yeah I think that’s the case here , reasonable assumptions were made, next.js just does things a little different from the norm I guess.

how is this done for express apps that need some production dependencies on runtime?

it uses webpack

soo, everything is bundled in

Updated: