Skip to content
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

NCC build fails when compiling a Custom Server NextJS app - ./static.edge is not exported from react-dom #1138

Closed
seanjb opened this issue Nov 15, 2023 · 3 comments

Comments

@seanjb
Copy link

seanjb commented Nov 15, 2023

Hoping someone can help as have been struggling to work around this.
I have a NextJS app that has a Custom Server (a typescript file server/index.ts transpiled to dist/index.js). The NextJS UI and server layer compile successfully and can be run without issue.

I have created a simplified copy of the repo here that demonstrates the issue. https://github.com/seanjb/nextjs-custom-server-ncc-issue
Npm scripts build and start work without issue. The package script (the NCC step) throws the error.

The Error thrown is:

Error: Module not found: Error: Package path ./server.edge is not exported from package C:\dev\test-ncc\node_modules\react-dom (see exports field in C:\dev\test-ncc\node_modules\react-dom\package.json)
Did you mean './react-dom/static.edge'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

I believe this server.edge component is specific to NextJS but not part of the official react-dom package (even though it appears in their main branch).

@styfle
Copy link
Member

styfle commented Dec 28, 2023

If you're using Next.js, I suggest using the built-in "standalone" mode instead of trying to manually bundle with ncc.

module.exports = {
  output: 'standalone',
}

https://nextjs.org/docs/app/api-reference/next-config-js/output

This is because ncc is meant for Node.js projects and doesn't know how to bundle frontend code or RSC or many other features that are used by Next.js

@imvad
Copy link

imvad commented Jan 23, 2024

@seanjb how did you solve it? I'm facing the same issue.

@seanjb
Copy link
Author

seanjb commented Jan 23, 2024

Hey @imvad we ended up using rollup to package the custom server.
We use next build and standalone to package the UI, then a server build step packages the server using rollup.

@styfle styfle closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
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