vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.51k stars 26.81k forks source link

When using export "standalone" inside a workspace it creates subfolders before server.js #56823

Open DevSlashRichie opened 11 months ago

DevSlashRichie commented 11 months ago

Link to the code that reproduces this issue

https://github.com/DevSlashRichie/brep

To Reproduce

I have the following project with turbo pack. when using output standalone with that tree of folders, it will create

image

module.exports = {
  reactStrictMode: true,
  transpilePackages: ["ui"],
  output: "standalone",  
};

Current vs. Expected behavior

Not sure if this is a problem (actually) but I guess it is since it shown when I run next start script the route without the padding folders.

So the expected behavior would be to only have standalone/server.js.

Verify canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep  7 13:12:03 UTC 2
Binaries:
  Node: 18.17.1
  npm: 9.6.7
  Yarn: 1.22.19
  pnpm: 8.6.5
Relevant Packages:
  next: 13.5.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.5.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Standalone mode (output: "standalone")

Additional context

No response

andyandrwew commented 11 months ago

I am having the same issue and when I run the build from Docker, I am getting completely stalled on the call to next build. I waited 600s in one attempt and it would not complete the call to next build

barnabycollins-s2z commented 9 months ago

I'm also getting this issue. I have a monorepo with Yarn Workspaces. My monorepo has a root directory with the global package.json and yarn.lock, and then immediately inside that directory I have a frontend directory which contains my Next project. The resulting structure in .next/standalone looks like:

image

The standalone build seems to depend on the node_modules outside the frontend folder, so unfortunately I can't just use the .next/standalone/frontend directory. The built application does work when launched with frontend/server.js, but is much larger than it needs to be as it includes modules that aren't needed for the frontend's production build.

I've found that the structure can be flattened by moving the contents of .next/standalone/node_modules into .next/standalone/frontend/node_modules and deleting the outer package.json, but this probably could result in unexpected behaviour with some configurations as you could end up overwriting some items, so I doubt it should be recommended.

Here's my next info output:

Operating System:
  Platform: linux
  Arch: x64
  Version: #40~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 16 10:53:04 UTC 2
Binaries:
  Node: 18.17.0
  npm: 9.6.7
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.0.3
  eslint-config-next: 14.0.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.9.5
Next.js Config:
  output: standalone

I also should mention the related discussion #35437.

AhmedBaset commented 8 months ago

I'm facing the exact same issue. You can find my production repository here with an unignored .next directory. You can check the build output directory on GitHub - there's no need to clone and build.

The repository is based on the @vercel/turbo's with-docker example with no modifications.

Upon running turbo build --filter web, I encountered two issues:

As a temporary solution, I've worked around this by modifying the Dockerfile as follows:

# Dockerfile

COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/standalone   ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/public             ./apps/web/public

# Move static folder to its correct place
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/static       ./apps/web/.next/static
COPY /apps/web/.env.local ./apps/web/.env.local
GravityTwoG commented 5 months ago

I have similar issue with nx in integrated mode. Repo: Link. After build in standalone mode i have this strange folder structure: image

I was able to dockerize app and it works. But I'm not sure if this behaviour of standalone mode is expected.

AlexBa commented 3 months ago

Still with same problem with Next 13, Yarn 3.8.2 with workspaces, Node 18 on Vercel. The standalone directory structure is not correct.

It's probably the cause of my issue on Vercel:

Error: Cannot find module 'next/dist/compiled/next-server/server.runtime.prod.js'
Require stack:
- /vercel/path0/apps/shop/noop.js

I'm already trying to fix this issue for about 16 hours and I tried everything from the internet (no joke).

DragosRomaniuc commented 2 months ago

@AlexBa Did you find a solution?

abcdefghiraj commented 3 weeks ago

Maybe my comment helps someone https://github.com/vercel/next.js/discussions/35437#discussioncomment-10596548 Long story short - if you are copying and/or zipping, preserve the symlinks in case of a monorepo.

BowgartField commented 2 days ago

Do you have any news on this bug ?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!