next.js icon indicating copy to clipboard operation
next.js copied to clipboard

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

Open DevSlashRichie opened this issue 1 year ago • 3 comments

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

  • [X] I verified that the issue exists in the latest Next.js 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

DevSlashRichie avatar Oct 14 '23 05:10 DevSlashRichie

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

andyandrwew avatar Oct 15 '23 20:10 andyandrwew

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.

barnabycollins-s2z avatar Dec 27 '23 16:12 barnabycollins-s2z

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:

  • I expect to receive output in the form of apps/web/.next/standalone/{server.js,.next,...}, but instead, I receive apps/web/.next/standalone/apps/web/{server.js,.next,...}. While this wouldn't be a major problem if it just moved the output to a sub-directory, the critical issue lies in the next point.
  • It generated the static directory at apps/web/.next/static instead of its correct location, which should be apps/web/.next/standalone/apps/web/.next/static. This results in a 404 not found error for all *.css, chunks, pre-optimized images, etc. since my app expects them at /_next/static/css/layout-2987whatever-id.css, /_next/static/chunks/app/page-4789whatever-id.js, etc.

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

AhmedBaset avatar Feb 01 '24 19:02 AhmedBaset

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.

GravityTwoG avatar May 07 '24 12:05 GravityTwoG

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).

AlexBa avatar Jun 21 '24 19:06 AlexBa

@AlexBa Did you find a solution?

DragosRomaniuc avatar Jul 20 '24 13:07 DragosRomaniuc