Next.js Discord

Discord Forum

issues with compiling/building a separate websocket server

Unanswered
vbhv posted this in #help-forum
Open in Discord
how to compile/build a separate websocket server , facing above issues , even tried to use some code from this https://github.com/trpc/examples-next-prisma-websockets-starter/blob/main/tsconfig.server.json
but it compiles the entire src code which is not needed ig

next build command builds the app but not the websocket server, due to which socket feature is not working in my app : ((

my tsconfig.json
{
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "ES2022",
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "checkJs": true,
    "lib": ["dom", "dom.iterable", "ES2022"],
    "noEmit": true,
    "moduleResolution": "bundler",
    "module": "esnext",
    "jsx": "preserve",
    "plugins": [
      {
        "name": "next"
      }
    ],
    "incremental": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./src/*"],
      "@/*": ["./src/*"]
    },
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    ".eslintrc.cjs",
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.cjs",
    "**/*.js",
    ".next/types/**/*.ts"
  ],
  "exclude": ["node_modules", "dist"]
}



tsconfig.server.json (for websocket server)

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "moduleResolution": "NodeNext",
    "module": "NodeNext",
    "outDir": "dist",
    "isolatedModules": false,
    "noEmit": false
  },
  "paths": {
    "~/*": ["./src/*"]
  },
  "include": [
    "src/server/wsServer.ts",
    "src/server/api/root.ts",
    "src/server/api/trpc.ts",
    "src/server/api/routers/**/*.ts",
    "src/server/db.ts",
    "src/env.ts"
  ],
  "exclude": [
    "node_modules",
    ".next",
    "**/*.test.ts",
    "**/*.spec.ts",
    "src/app",
    "src/components",
    "src/**/*.tsx"
  ]
}

3 Replies

and my build scripts from package.json

  "scripts": {
    "build:1-next": "cross-env next build",
    "build:2-server": "tsc --project tsconfig.server.json",
    "build": "run-s clean build:*",
this is fixed , thanks
Lesser Frigatebird
Could you provide details on how did you fixed this issue?