Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling too slow on next 9.4 #12797

Closed
ranjithkumar8352 opened this issue May 12, 2020 · 35 comments · Fixed by #12909
Closed

Compiling too slow on next 9.4 #12797

ranjithkumar8352 opened this issue May 12, 2020 · 35 comments · Fixed by #12909
Milestone

Comments

@ranjithkumar8352
Copy link

ranjithkumar8352 commented May 12, 2020

Maintainer update

Please see #29559 (comment)


Bug report

Describe the bug

Hello, I just upgraded next from 9.3 to 9.4 today. It seems that compiling a single page takes too long. More than 3 minutes. Sometimes it never compiles too.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Install next 9.4
  2. run next dev and start the server
  3. Go to any page in localhost:3000
  4. It takes a very long time to compile and even it compiles, the page never loads on browser sometimes.

Expected behavior

It should compile the page faster (usually 5 to 10 seconds) and load the page.

Screenshots

image

System information

  • OS: Windows
  • Version of Next.js: 9.4
  • Version of Node.js: 12.16.3
@Timer Timer added Type: Needs Investigation please add a complete reproduction The issue lacks information for further investigation labels May 12, 2020
@Timer
Copy link
Member

Timer commented May 12, 2020

Could you please give us a full reproduction? We'll need it to reproduce and track this down. 🙏

@ranjithkumar8352
Copy link
Author

@Timer Its a private codebase.
Here's the package.json

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "build:staging": "cross-env NEXT_PUBLIC_ENV=staging next build",
    "start": "next start -p 8081",
    "start:staging": "cross-env NEXT_PUBLIC_ENV=staging next start -p 8081"
  },
  "dependencies": {
    "@stripe/stripe-js": "^1.5.0",
    "@zeit/next-sass": "^1.0.1",
    "aws-amplify": "^3.0.8",
    "bulma": "^0.8.2",
    "graphql-tag": "^2.10.3",
    "mobx": "4.x",
    "mobx-react": "^6.2.2",
    "next": "^9.4.0",
    "node-fetch": "^2.6.0",
    "node-sass": "^4.13.1",
    "nookies": "^2.2.2",
    "nprogress": "^0.2.0",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native-web": "^0.12.2"
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/plugin-proposal-decorators": "^7.8.3",
    "@react-native-community/eslint-config": "^1.0.0",
    "babel-plugin-react-native-web": "^0.12.2",
    "cross-env": "^7.0.2",
    "eslint": "^6.8.0"
  }
}

It takes too long to compile even for a page with a single div. Can you tell me what other details should I share?

@Timer
Copy link
Member

Timer commented May 12, 2020

Sorry, but we'll need a full demo to provide any more insights. You can try to reduce your app to a single page without private data.

@SelvinM
Copy link

SelvinM commented May 12, 2020

I'm having the same problem

1 similar comment
@s-kris
Copy link

s-kris commented May 13, 2020

I'm having the same problem

@Timer
Copy link
Member

Timer commented May 13, 2020

Hi everyone!

Replying with "+1"s do not help us prioritize this issue any quicker. If you'd like us to fix this problem, please provide a reproducible demo.

Thanks!

@s-kris
Copy link

s-kris commented May 13, 2020

Hey @Timer,
Here it is: https://github.com/s-kris/loading-test

Steps to reproduce:

  1. Clone above repo && run yarn dev && go to localhost:3000.
  2. Click on click here to go to test page.
  3. Hit refresh button on browser.
  4. Click back button on browser.
  5. Repeat steps 2, 3 & 4. Hit refresh. You can see that page loads forever. Closing the tab and loading localhost:3000 doesn't fix either.

Video: https://www.youtube.com/watch?v=orS_6SbEafc

@Timer
Copy link
Member

Timer commented May 13, 2020

Thank you! We'll look at this soon.

@Timer Timer removed the please add a complete reproduction The issue lacks information for further investigation label May 13, 2020
@Timer Timer added this to the 9.4.1 milestone May 13, 2020
@ghost
Copy link

ghost commented May 14, 2020

Thanks @Timer I'm having the same issue here with a very small project too...

@timneutkens
Copy link
Member

Thanks @Timer I'm having the same issue here with a very small project too...

@mahmoudm-mvsi, As said by @Timer:

Replying with "+1"s do not help us prioritize this issue any quicker. If you'd like us to fix this problem, please provide a reproducible demo.

Your comment does not add to this issue and is the equivalent to saying +1. Please use GitHub's emoji reactions if you want to "+1" an issue.

@Timer
Copy link
Member

Timer commented May 15, 2020

Could everyone please try next@9.4.1-canary.5 and see if that resolves their speed issue?

@ranjithkumar8352
Copy link
Author

@Timer It is resolved in next@9.4.1-canary.5 Thanks for the quick fix!

@Timer
Copy link
Member

Timer commented May 15, 2020

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.

@ranjithkumar8352
Copy link
Author

That's interesting!

@s-kris
Copy link

s-kris commented May 15, 2020

@Timer It's fixed now, thanks! But I'm on MacOS 10.15.4!

@Timer
Copy link
Member

Timer commented May 15, 2020

@s-kris the repo you posted was something else that's still a bug: #5598. There's an open version somewhere.

@s-kris
Copy link

s-kris commented May 15, 2020

Just checked #5598, interesting. On the first try it seemed to be fixed but I'll keep a track on this (not using nextjs currently for any active projects).

@Timer
Copy link
Member

Timer commented May 15, 2020

We're planning on fixing it as part of webpack 5, which is coming 🔜!

@ghost
Copy link

ghost commented May 16, 2020

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.

I'm really curious to know how did you find out about that! lol

@timneutkens
Copy link
Member

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.

I'm really curious to know how did you find out about that! lol

Profiling together with @sokra

@mosesoak
Copy link

Wow, this issue saved me a headache, thank you @Timer!!! It looks like HMR was disabled by Windows Defender: when on, Next was doing a full rebuild / page refresh, ~20 seconds vs ~1 second. Huge diff.

Here's where you turn it off: click the Manage Settings link in Settings > Security > Virus & Threat Protection. Note that it says it will turn itself back on after some amount of time. Anyone know how to configure it? I dug around in Control Panel and couldn't find anything.

image

@mosesoak
Copy link

Wondering if this issue might be key to fixing this? Obviously we don't want to have to disable security on our machine just to use Next! #14266

@Timer
Copy link
Member

Timer commented Jul 17, 2020

That is the correct issue to follow, @mosesoak!

@mosesoak
Copy link

mosesoak commented Jul 17, 2020

Cool thanks. Just found out from a very smart friend that you can fix the issue more cleanly by leaving Defender turned on but setting your project folder as an Exception:

image

(Scroll down on the Virus & threat protection settings page to find this)

Add:

  • Folder: your main projects folder
  • Process: node
  • Process: wslhost.exe (if you use WSL)

@tom1mat
Copy link

tom1mat commented Aug 1, 2020

Hi guys! Firstly thank you for your awesome support always!! @Timer @timneutkens
I am having the same problem stated in the issue description in macOS Mojava 10.14.6.
I tried with next@9.4.1-canary.5 and the last next@9.5.1 and I'm still getting the loop.

Tested in Ubuntu and it works well.

Package Json:

{
  "name": "web-porpora",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "start-dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@babel/polyfill": "^7.10.1",
    "@material-ui/core": "^4.10.2",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.56",
    "@sendgrid/mail": "^7.2.1",
    "@zeit/next-sass": "^1.0.1",
    "bcrypt": "^5.0.0",
    "classnames": "^2.2.6",
    "cookie": "^0.4.1",
    "debounce": "^1.2.0",
    "dotenv": "^8.2.0",
    "formidable": "^1.2.2",
    "formik": "^2.1.4",
    "js-cookie": "^2.2.1",
    "jsonwebtoken": "^8.5.1",
    "mysql": "^2.18.1",
    "next": "^9.5.1",
    "node-sass": "^4.14.1",
    "react": "16.13.1",
    "react-click-outside": "github:tj/react-click-outside",
    "react-dom": "16.13.1",
    "react-dropzone": "^11.0.2",
    "react-table": "^7.2.1",
    "s": "^1.0.0",
    "yup": "^0.29.1"
  },
  "devDependencies": {
    "@types/node": "^14.0.6",
    "@types/react": "^16.9.35",
    "@types/react-dom": "^16.9.8"
  }
}

next.config

const withSass = require('@zeit/next-sass')
module.exports = withSass({
  webpack: (config, { isServer }) => {
    // Fixes npm packages that depend on `fs` module
    if (!isServer) {
      config.node = {
        fs: 'empty'
      }
    }

    return config
  }
})

.babelrc

{
  "presets": [
    [
      "next/babel",
      {
        "preset-env": {},
        "transform-runtime": {},
        "styled-jsx": {},
        "class-properties": {}
      }
    ]
  ],
  "plugins": []
}

@PrimeObjects
Copy link

PrimeObjects commented Aug 13, 2020

"next": "9.5.2"
Got the same slow, and the webpack took around 30 s
image

@timneutkens
Copy link
Member

webpack-hmr is only an eventsource connection that stays open hence why the time keeps running, it's unrelated to webpack compilation times.

@asdofindia
Copy link

I just want to add a comment here although it is definitely not the problem that others faced.

I was having slow compilation time on Ubuntu. The problem was that I had graalvm installed and the "node" binary that was getting executed was the one provided by graalvm. Removing that from the $PATH solved the issue.

This might help someone.

@seyedasfar
Copy link

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.

but I'm using Ubuntu.

@vgb0332
Copy link

vgb0332 commented Mar 16, 2021

Everyone I've been having the exact same issue for a long time and tried every possible solution I could find on the internet.
And I finally found an answer to my case. i hope it helps some people with similar problems.

My project uses quill, ckeditor, less, ant design for third libraries and had to configure next.config.js for them.
I figured their configurations require massive amount of regex check which have caused the slow build issue(even heap out of memory issue).

I haven't been able to find an alternative to fasten things up with these configuration.
But my recommendation is for 'dev' environment slash these configuration setting unless really important or necessary.

@dailytravel
Copy link

NextJS compile slow after I try test with pwa. You need clear data from application as the bellow to fix it!
image

@erfanasbari
Copy link

erfanasbari commented Aug 12, 2021

My project took around 30sec for a page to compile and it took around 10 seconds for hot reloading, also the ram usage was very high (4 Gb on mac) and after a while I ran into Javascript heap out of memory and I had to restart the dev server. I tried a lot of methods but it wasn't working. I analyzed the bundle using @next/bundle-analyzer and I saw react-icons was the largest package that was being parsed. So I went to react-icons NPM page and saw this:

If your project grows in size, this option is available. This method has the trade-off that it takes a long time to install the package.

yarn add @react-icons/all-files
# or
npm install @react-icons/all-files --save

Example usage:

import { FaBeer } from "@react-icons/all-files/fa/FaBeer";
class Question extends React.Component {
  render() {
    return <h3> Lets go for a <FaBeer />? </h3>
  }
}

So I did that and the ram usage decreased by 3 Gb and the compile time decreased as well and now everything is ok.
Note: you can apply the same method for other libraries like @material-ui/icons

My project was ok on react and I don't know why next has some problems with importing a single value from a large module.

@CrispenGari
Copy link

I've tried all these mentioned methods none of them worked on my situation. Developing in nextjs is becoming a pain. Can you guys improve this on windows we are suffering and its stressful spending half of a day staring on the browser waiting for the code to compile only to find out that you have an error. Im coming beck to nextjs when this bug is fixed, for now let me use gasty and react.

@SSylvain1989
Copy link

Hello same issue here im on mac m1 chip ... i have to close my chrome and reopen for fast compile ...

@timneutkens
Copy link
Member

FYI I'm tracking a new thread here: #29559 (comment)

@vercel vercel locked and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.