nrwl / nx

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

Next.js error: "Source and destination must not be the same" #4416

Closed cyrus-za closed 3 years ago

cyrus-za commented 3 years ago

Renovate bot opened a PR to upgrade from 11.0.18 to 11.0.20 and my nextjs build failed with error

Source and destination must not be the same.
image

I am using @JamesHenry's build-nextjs-app-on-vercel.sh script. The entire next build completes on vercel, but then when it is meant to create the serverless functions on the edges, it throws the above error.

image

This is most likely relate to https://github.com/serverless-nextjs/serverless-next.js/issues/461

Everything works fine on 11.0.18. I am simply not going to merge that PR in, and keep going until this is solved. I just figured I'd point it out.

PS. I know, I should use nx migrate and not manually update deps, which is exactly what I do when I see a nx related PR from renovate. I ran that and there was no migrations.json file this time around and no other packages other than those listed above got updated with it, so it's essentially the same PR this time around.

akash6190 commented 3 years ago

I think nx doesn't allow both and source and build as the same request, I updated the last line so I can build to its normal location and then move it to the required folder as a workaround.

NODE_ENV=production npm run nx -- build $1 --prod
mv -vf dist/apps/$1/.next $2/
mv -vf dist/apps/$1/package.json $2/package.json
cyrus-za commented 3 years ago

Thanks. That solved it for me. I'll keep the issue open until @JamesHenry responds though. Might be a better workaround

cyrus-za commented 3 years ago

Every now and then I get an error that the .next directory already exists. Seems like a vercel caching thing. @akash6190 you running into this too?

JamesHenry commented 3 years ago

The combination of some updates on the Vercel side and this PR: https://github.com/nrwl/nx/pull/4459 will mean that the extra build script should no longer be required and the Vercel UI setup can be simplified.

We have a thread going with Vercel on this, and I will update the instructions as soon as we have confirmation on all sides

I would say just hang tight on whatever works for you in the interim

JamesHenry commented 3 years ago

Hi folks 👋

We have worked together with Vercel to improve the configuration required to deploy Next.js apps on Vercel from Nx workspaces. Additional/custom scripts are no longer required.

Please see the updated guidance here https://github.com/nrwl/nx/pull/4483, it is available for you to implement immediately.

Once the PR is merged, the updated guidance will also be available on https://nx.dev/latest/react/guides/nextjs

Thanks!

cyrus-za commented 3 years ago

Thanks @JamesHenry. That fix works for me. I've left some comments in #3051 for other users with similar issues.

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.