question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

next.js recipe disjoint customServer provisions between build & serve

See original GitHub issue

Current Behavior

  • serve supports a customServer, but build is missing such provisions. that is, though i have a custom server, the build distribution ignores it, meaning my built artifact is not runnable after build, but is runnable in dev using serve.

similarly, next.config.js & public assets are missing in dist, which are common next.js required artifacts

this is related, but independent of #3190

Expected Behavior

  • customServer and associated provisions make it into dist. this could feasibly be a webpack::target::node execution on customServer placed into dist/apps/<appname>/server.js as an optimized bundle.

Steps to Reproduce

  • observe nx src for next.js serve vs build builder impls

Failure Logs

n/a

Environment

n/a

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
jaysoocommented, Jun 14, 2022

Sorry for the lack of updates. We need to rethink the custom server implementation.

As pointed out, it is only running the dev server through the custom server. We may need a migration to move it from @nrwl/next:server to @nrwl/next:build since it is a build concern.

We’ll have something soon, so stay tuned.

3reactions
nsmith7989commented, Aug 10, 2021

@kirjai I don’t think #5765 fixes this issue for build.

The custom server never ends up compiled into the dist directory.

Also if you look at the dist’s package.json of each app, start is still "start": "next start" not "start": "node customServer.js"

We’re run into this problem too, ended up adding a separate target to each of our nextjs apps that does @nrwl/node:build, then use @nrwl/workspace:run-commands to combine those two together.

"build": {
          "executor": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
              "yarn nx run booking-res-lite:build-next:production",
              "yarn nx run booking-res-lite:build-server:production"
            ]
          }
        },
        "build-next": {
          "executor": "@nrwl/next:build",
          "outputs": ["{options.outputPath}"],
          "options": {
            "root": "apps/booking/res-lite",
            "outputPath": "dist/apps/booking-res-lite"
          },
          "configurations": {
            "production": {}
          }
        },
        "build-server": {
          "executor": "@nrwl/node:build",
          "outputs": ["{options.outputPath}"],
          "options": {
            "outputPath": "dist/apps/booking-res-lite",
            "main": "apps/booking/res-lite/server.ts",
            "tsConfig": "apps/booking/res-lite/tsconfig.server.json"
          },
          "configurations": {
            "production": {
              "optimization": true,
              "extractLicenses": true,
              "inspect": false
            }
          }
        },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Custom Server - Next.js
If your project uses a custom server, this behavior may result in the same content being served from multiple paths, which can present...
Read more >
Getting Started | Next.js
Get started with Next.js in the official documentation, and learn more about all our features!
Read more >
next/server - Next.js
The NextRequest object is an extension of the native Request interface, with the following added methods and properties: cookies - A RequestCookies instance ......
Read more >
Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >
Going to Production - Next.js
For best results, use a production build of Next.js and use incognito in your ... to immutable assets served from /_next/static including JavaScript,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found