Skip to content

How to bundle nextjs as a SEA #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
samsamurai301 opened this issue Apr 25, 2025 · 4 comments
Open

How to bundle nextjs as a SEA #121

samsamurai301 opened this issue Apr 25, 2025 · 4 comments

Comments

@samsamurai301
Copy link


Goal:

I am trying to create a standalone .exe (Windows executable) bundle of a Next.js application. My goal is to package the entire app, along with the Node.js runtime, into a single executable file that can be run on a Windows machine without requiring Node.js to be installed.

What I've Tried:

I've followed the Next.js standalone export process (output: 'standalone') and attempted to bundle it using the Node.js Self-Extracting Archive (SEA) feature, as described in the [official Node SEA documentation](https://nodejs.org/api/single-executable-applications.html). This process is relatively new and intended to replace older tools like pkg and nexe.

Previously, I was able to generate .exe files using:

However, both of these tools are now either unmaintained or lacking support for modern Node.js features and complex setups like those involving Next.js and ES modules.

Challenges:

  • While I can get a working output using next build with output: 'standalone', integrating this with the SEA approach is proving difficult.
  • The SEA process requires setting up a bootstrap loader script (loader.js), embedding it into a Node binary, and including the blob containing the app code.
  • Next.js apps have complex file structures (e.g., dynamic imports, middleware, server components), which makes packaging and referencing assets non-trivial.
  • There’s little guidance available on combining Next.js with SEA to generate an actual Windows .exe file.

What I’m Looking For:

I need a reliable, maintainable method for turning a Next.js application into a Windows executable using:

  • Modern tooling (preferably SEA or other actively maintained methods),
  • Node.js 18+ compatibility, and
  • Support for standalone server builds generated by Next.js.

If anyone has successfully used Node SEA with a Next.js app, or has a working example or boilerplate for generating .exe files from a standalone build, I’d greatly appreciate any guidance or resources you could share.

@cspotcode
Copy link

Does deno compile with --include do the trick?

--include tells it to bundle an entire directory of files so they can be referenced as dynamic imports at runtime. Your requirements list "Node.js 18+ compatibility" which is hopefully achieved with deno's node compat, though of course bugs may exist. Their website has a page on "Next.js" which suggests Next.js has been tested and is working.

@BYK
Copy link

BYK commented Apr 30, 2025

@samsamurai301 -- I created https://github.com/BYK/fossilize to make using Node SEA easier and I think with some modifications, it can support Next.js projects directly. Right now it supports automatically embedding assets using a manifest.json file from Vite but your app still needs to be aware that it is being packaged and needs to know how to read these files using the node:sea module APIs.

The way I use it currently is this little hack: https://github.com/getsentry/spotlight/blob/b09723c797fc9a537bf2e104a945f5979139781b/packages/spotlight/bin/run.js#L32-L41

Does that help? I'm happy to collaborate on this.

@samsamurai301
Copy link
Author

samsamurai301 commented May 5, 2025

Does deno compile with --include do the trick?

--include tells it to bundle an entire directory of files so they can be referenced as dynamic imports at runtime. Your requirements list "Node.js 18+ compatibility" which is hopefully achieved with deno's node compat, though of course bugs may exist. Their website has a page on "Next.js" which suggests Next.js has been tested and is working.

@cspotcode For this I have to create a complete new project instead of modify in existing one, But for new project where I am needing something like that I will use the approach you wrote, Thanks for the help.

@cspotcode
Copy link

cspotcode commented May 5, 2025

@samsamurai301

For this I have to create a complete new project instead of modify in existing one

Not really, no, it can run existing nodejs projects. I wouldn't have suggested it otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants