Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Unanswered
DevSlashRichie asked this question in Help
Discussion options

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

  • 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

You must be logged in to vote

Replies: 9 comments

Comment options

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

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
0 replies
Comment options

@AlexBa Did you find a solution?

You must be logged in to vote
0 replies
Comment options

Maybe my comment helps someone #35437 (comment)
Long story short - if you are copying and/or zipping, preserve the symlinks in case of a monorepo.

You must be logged in to vote
0 replies

This comment was marked as off-topic.

Comment options

Hi everyone—

Standalone mode was designed to be "minimal," meaning that static files are not copied over → https://nextjs.org/docs/app/api-reference/next-config-js/output#automatically-copying-traced-files.

This discussion (and the comment above) may prove helpful in providence guidance to get the right configuration going!

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
bug Issue was opened via the bug report template. Output Related to the the output configuration option.
Converted from issue

This discussion was converted from issue #56823 on November 06, 2024 23:14.

AltStyle によって変換されたページ (->オリジナル) /