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

can't serve next app in production after generating a custom-server with @nrwl/next:custom-server #14507

Closed
ericschaal opened this issue Jan 19, 2023 · 4 comments · Fixed by #14553
Assignees
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: bug

Comments

@ericschaal
Copy link

Current Behavior

Running the following on a next app with a custom server

nx build
nx serve --configuration=production

Throws the following error

Error: Could not find a production build in the '[private-path]/apps/useronboarding/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
    at NextNodeServer.getBuildId ([private-path]/node_modules/next/server/next-server.ts:347:15)
    at new Server ([private-path]/node_modules/next/server/base-server.ts:357:25)
    at new NextNodeServer ([private-path]/node_modules/next/server/next-server.ts:215:5)
    at NextServer.createServer ([private-path]/node_modules/next/server/next.ts:140:12)
    at [private-path]/node_modules/next/server/next.ts:159:23
    at NextServer.prepare ([private-path]/node_modules/next/server/next.ts:125:20)

Expected Behavior

Running

nx build
nx serve --configuration=production

should run the next application with a custom server

Github Repo

https://github.com/ericschaal/nx-bug

Steps to Reproduce

Reproduction repository has been generated as such:

npx create-nx-workspace@latest --preset=next
nx g custom-server nx-bug

To reproduce:

npm install
nx build nx-bug
nx serve nx-bug --configuration=production

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 16.18.0
   OS   : darwin x64
   npm  : 8.19.2
   
   nx : 15.2.1
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.2.1
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.2.1
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.2.1
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.2.1
   @nrwl/js : 15.2.1
   @nrwl/linter : 15.2.1
   @nrwl/nest : Not Found
   @nrwl/next : 15.2.1
   @nrwl/node : 15.2.1
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.2.1
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.2.1
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.2.1
   @nrwl/web : 15.2.1
   @nrwl/webpack : 15.2.1
   @nrwl/workspace : 15.2.1
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

Error: Could not find a production build in the '[private-path]/apps/useronboarding/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
    at NextNodeServer.getBuildId ([private-path]/node_modules/next/server/next-server.ts:347:15)
    at new Server ([private-path]/node_modules/next/server/base-server.ts:357:25)
    at new NextNodeServer ([private-path]/node_modules/next/server/next-server.ts:215:5)
    at NextServer.createServer ([private-path]/node_modules/next/server/next.ts:140:12)
    at [private-path]/node_modules/next/server/next.ts:159:23
    at NextServer.prepare ([private-path]/node_modules/next/server/next.ts:125:20)

Additional Information

No response

@ericschaal ericschaal changed the title @nrwl/next can't run serve production after generating a custom-server with @nrwl/next:custom-server can't run serve next app in production after generating a custom-server with @nrwl/next:custom-server Jan 19, 2023
@ericschaal ericschaal changed the title can't run serve next app in production after generating a custom-server with @nrwl/next:custom-server can't serve next app in production after generating a custom-server with @nrwl/next:custom-server Jan 19, 2023
@AgentEnder AgentEnder added the scope: nextjs Issues related to NextJS support for Nx label Jan 23, 2023
@ndcunningham
Copy link
Contributor

It looks like the path which we are looking for in the production build is incorrect.
We will address this

@marianzburlea
Copy link

Hi @ndcunningham . Is it possible that this issue is the same as:

image

I can see the file generated during the build process that is dealing with types has a wrong path:

image

if it's not related, should I open a new issue?

All I need to do to reproduces it is to enable app dir:

image

in a NextJS project.

While running nx serve my-next, the appDir works fine,
when running nx build my-next, the error above happens.

@xegulon
Copy link

xegulon commented Feb 9, 2023

@AgentEnder what about @marianzburlea's issue?

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: bug
Projects
None yet
5 participants