0

Created a website using next.js with both backend and frontend in one project.In production it takes so much of time to load a webpage.Next version is 9.3.0. this is my script.using of scss effects loading time

package.json

"scripts": {
    "dev": "ts-node --compiler-options=\"{\\\"module\\\": \\\"commonjs\\\"}\" server/server.ts",
    "build": "next build",
    "start": "NODE_ENV=production 'ts-node' --compiler-options=\"{\\\"module\\\": \\\"commonjs\\\"}\" server/server.ts"
}
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Karthi
  • 3,019
  • 9
  • 36
  • 54

2 Answers2

2

I guess that you are starting your production app using npm run start. From it, it looks like you are running ts-node on production (which compiles TS on the fly).

It is better to compile server.ts on build step using typescript into dist or something like this, then run node on a js result inside dist folder.

felixmosh
  • 32,615
  • 9
  • 69
  • 88
  • Had the same issue and this helped speed a lot. I have `server.js` instead of `.ts` but everything else is in `ts/tsx`. Next does already have a loader for these files it seems, so no need for ts-node. – David Min Aug 18 '21 at 11:44
0
  1. https://github.com/vercel/next.js/issues/12797#issuecomment-629321790
  2. https://github.com/vercel/next.js/issues/12797#issuecomment-660225689

For those curious, this was caused by Windows Defender. Windows Defender was delaying the HMR (to do a scan) because our emitted JavaScript files contained the word eval! That's why macOS was unaffected.

Chukwuemeka Maduekwe
  • 6,687
  • 5
  • 44
  • 67