#Custom server issue with latest version of Next

4 messages · Page 1 of 1 (latest)

mighty dawnBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

stark cloud
#

This happens when using a custom server. I created a NextJS app with create-next-app with the latest version of next, and created a custom server.

server/index.ts

import express, { Application, Request, Response } from "express"
import { createServer } from "http"
import next from "next"
import url from "url"

const dev = process.env.NODE_ENV !== "production"
const nextApp = next({ dev })
const nextHandler = nextApp.getRequestHandler()

nextApp.prepare().then(() => {
    const app: Application = express()

    app.all("*", function handler(req: Request, res: Response) {
        const parsedUrl = url.parse(req.url, true)
        nextHandler(req, res, parsedUrl)
    })

    const server = createServer(app)

    try {
        const port = parseInt(process.env.PORT || "3000", 10)
        server.listen(port)
        console.log("Server listening on port", port)
    } catch (error) {
        console.log(error)
    }
})

When running yarn run dev, it executes the command nodemon. Here is the nodemon.json file:

nodemon.json

{
    "watch": ["server", "src", "shared"],
    "exec": "ts-node --project tsconfig.server.json server/index.ts",
    "ext": "js ts"
}
#

And here are the tsconfig files:
tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"],
  "ts-node": {
    "transpileOnly": true,
    // "swc": true
  }
}

tsconfig.server.json

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
      "module": "commonjs",
      "outDir": "dist",
      "target": "es2019",
      "isolatedModules": false,
      "noEmit": false,
    },
    "include": [
      "server/**/*.ts",
    ]
}
#

Custom server issue with last version of Next