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 9 with custom server(typescript)

See original GitHub issue

Question about Next.js

before next9 it worked just fine but after upgrading it won’t work is there solution for it??

the tsconfig.json file is

{
  "compilerOptions": {
    "outDir": "./build",
    "allowJs": true,
    "target": "esnext",
    "lib": ["es2015", "es2016", "es2017", "es2018", "dom"],
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "downlevelIteration": true,
    "sourceMap": true,
    "typeRoots": ["./@types", "./node_moduels/@types"],
    "baseUrl": "./",
    "paths": {
      "*": ["@types/*"]
    },
    "strict": true,
    "removeComments": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": ["./**/*"],
  "exclude": ["node_moduels", "./build"]
}

and package.json file is

 "d": "rm -rf build && cross-env NODE_ENV=development tsc-watch -p tsconfig.json --onSuccess \"node build/index.js\"",

and the error code is

Error: Cannot find module '/Users/peter/Server/theSeed/build/index.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

it won’t build properly 😦

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
pateketucommented, Nov 6, 2019

custom-server-typescript example is great, but when running ts-node when you make changes to server/index.ts then it takes good 20-30 sec for the app to re-start as nextjs is deleting the .next folder content and re-generating it, any way to optimize rebuilding of nextjs folder when changes are not in any pages?

2reactions
andresgutgoncommented, Dec 22, 2019

I managed to have next js code hot reloaded by adding this to next.config.js

module.exports = {
  webpackDevMiddleware: config => {
    config.watchOptions = {
      poll: 800,
      aggregateTimeout: 300,
    }
    return config
  },
}

Important: I’m running my app in a Docker container with docker-compose.yml. So maybe this is not necessary if you’re running the app in your machine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set Up Next.js with a Custom Express Server + Typescript
In this post, I will walk you through how to make a Next.js application handled by a custom Express server with Typescript.
Read more >
Next.js Custom Server Typescript Example - StackBlitz
Run official live example code for Next.js Custom Server Typescript, created by Vercel on StackBlitz.
Read more >
zeit/next.js: custom-server-typescript - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Advanced Features: Custom Server - Next.js
A custom Next.js server allows you to start a server 100% programmatically in order to use custom server patterns. Most of the time,...
Read more >
Custom NextJS Server with Typescript - DEV Community ‍ ‍
There is an official NextJS guide on how to create a custom server. However, it only works with JavaScript. Please follow their guide...
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