Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Next.js with webpack 5 hangs on first compile (.next folder is empty) #54

Closed
vvo opened this issue Mar 16, 2021 · 10 comments · Fixed by vercel/next.js#23224
Closed

Next.js with webpack 5 hangs on first compile (.next folder is empty) #54

vvo opened this issue Mar 16, 2021 · 10 comments · Fixed by vercel/next.js#23224
Assignees

Comments

@vvo
Copy link

vvo commented Mar 16, 2021

Hey there, using a brand new create-next-app, using webpack 5, all dependencies up to date, following the tailwindcss-jit README then on first load (when .next folder is empty) the build never finishes.

You have to CTRL+C and then start again for it to work.

Example repo: https://github.com/vvo/tailwindcss-jit-hangs-webpack5-next.js

git clone git@github.com:vvo/tailwindcss-jit-hangs-webpack5-next.js.git
cd tailwindcss-jit-hangs-webpack5-next
yarn && yarn dev

Now try to load http://localhost:3000 and it will hang forever.
If you restart the server it will work.

To reproduce the hang, rm -rf .next.

Disabling webpack 5 solves this issue, using webpack 5 using regular tailwindcss works.

PS: On my real-world project, the build never finishes at all, first load or second load, I could not reproduce this behavior though 🤷

@utkarshkukreti
Copy link

Can confirm the dev build never finishes on my project with Next.js + webpack 5, no matter how many times I restart the server.

With DEBUG=1, I can see that the JIT compilation is working:

Source path: .../index.css
Setting up new context...
Reading changed files: 0.605ms
Generate rules: 6.206ms
Build stylesheet: 0.255ms
Changed files:  4
Potential classes:  113
Active contexts:  1
Content match entries 38
JIT TOTAL: 185.58ms

Source path: .../index.css
Reading changed files: 0.004ms
Generate rules: 0.108ms
Build stylesheet: 0.003ms
Changed files:  0
Potential classes:  1
Active contexts:  1
Content match entries 38
JIT TOTAL: 6.254ms

@adamwathan
Copy link
Member

adamwathan commented Mar 16, 2021

I suspect is this because NODE_ENV is set to development. Either set it to production or set TAILWIND_MODE=build. We run a bunch of watchers in the background for watching template changes and by default we set those up if NODE_ENV is development or TAILWIND_MODE is watch.

image

@utkarshkukreti
Copy link

That was actually the first thing I tried, but it didn't work. I patched this package to confirm that TAILWIND_MODE is being correctly set:

image

image

Btw, next build runs fine (and fast!). The problem is only in next dev.

@vvo
Copy link
Author

vvo commented Mar 16, 2021

@adamwathan NODE_ENV is development on my side yes because I use next dev.

The bug shows when next dev is used.
The bug is not present when not using webpack 5.

@joneath
Copy link

joneath commented Mar 17, 2021

I am also seeing next hang when using webpack 5. Dropping to webpack 4 fixes the problem but it would be great to have both the tailwind JIT and webpack 5 filesystem caching running together.

@bradlc
Copy link
Contributor

bradlc commented Mar 17, 2021

I have opened an issue over on vercel/next.js for this, and it looks like there's already a pull request over on webpack/webpack to address the issue 🙌 Hopefully it won't be too long before a fix lands in Next.js, but for now you can either disable webpack 5, or use Next.js version 10.0.8. Will keep this open for now and will try to keep you updated 👍

@utkarshkukreti
Copy link

@bradlc thanks for looking into this! I tried downgrading next.js: 10.0.7 works fine, but for some reason 10.0.8 hangs for me just like 10.0.9. Anyways, since it works with 10.0.7, the problem is not in this package.

@bradlc bradlc self-assigned this Mar 19, 2021
kodiakhq bot pushed a commit to vercel/next.js that referenced this issue Mar 22, 2021
fixes #23125

fixes tailwindlabs/tailwindcss-jit#54

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
@bradlc
Copy link
Contributor

bradlc commented Mar 22, 2021

The latest canary version of next (10.0.10-canary.7) resolves this issue 🙌 Thanks to @sokra for the fix!

@utkarshkukreti
Copy link

Thanks @sokra @bradlc, I can confirm @tailwindcss/jit works with 10.0.10-canary.7 with webpack 5 in dev mode!

@adamwathan
Copy link
Member

Awesome, going to close then — thanks @sokra!

flybayer pushed a commit to blitz-js/next.js that referenced this issue Apr 29, 2021
fixes vercel#23125

fixes tailwindlabs/tailwindcss-jit#54

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
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.

5 participants