nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.03k stars 2.3k forks source link

Next js: Easily deploy to Zeit vercel #3051

Closed asherccohen closed 3 years ago

asherccohen commented 4 years ago

Expected Behavior

Deploy to Zeit Vercel with a simple command.

Current Behavior

Current 'build' structure works for platforms like Heroku but not on Zeit Vercel, as we can't push the .next folder. Like this we miss all the cool features this hosting platform gives like static hosting to CDN!

Failure Information (for bugs)

Zeit Vercel is very strict on how to deploy a next js project since it needs to accomodate for many factors (paths/api routes/deps/env variables etcs), therefore prefers building on their hosting provider. It also ignores .next folders (there's a trick to push this by using a .vercelignore file, but doesn't help anyway)

The current implementation of next js plugin for nx dev is great, it can easily create a .next folder and copy assets to dist/myApp, it also generates a basic package.json (to which we have to manually add deps).

This structure is ready for platforms like Heroku, where we can push over the .next folder (build artifacts which include shared libs and typescript related compilation), have heroku install node_modules then run the project.

The only solution I have found is to avoid building altogether. What I do:

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. generate a next app
  2. add some dependencies (like date-fns or some other library) and use it in the app.
  3. import and use a shared lib
  4. nx build myNextJSApp
  5. Try to deploy to Zeit Vercel (REMEMBER that .next folder will not be pushed to Vercel)
Rafcin commented 2 years ago

For vercel you can just set the build script to be nx build appname --prod and it will work just fine.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.