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

Async PostCSS Plugin on Windows 10 with too many parsed files (~10k) yields a webpack error (EMFILE: too many open files) #12069

Closed
akehir opened this issue Sep 22, 2023 · 4 comments · Fixed by #12079
Assignees

Comments

@akehir
Copy link

akehir commented Sep 22, 2023

What version of Tailwind CSS are you using?

v3.3.3

What build tool (or framework if it abstracts the build tool) are you using?

    "@angular/cli": "~16.2.3",
    "autoprefixer": "10.4.16",
    "postcss": "8.4.30",
    "tailwindcss": "3.3.3",

What version of Node.js are you using?

For example: v18.18.0

What browser are you using?

N/A

What operating system are you using?

Windows 10, 22H2

Reproduction URL
https://github.com/akehir/tailwindowsbugger

Describe your issue

After upgrading to tailwind 3.3.3 (from 3.3.2) we faced an issue with npm start (or ng serve), with the error EMFILE: too many open files`. From my analysis, the bug is introduced in the PR when postcss was made async ( https://github.com/tailwindlabs/tailwindcss/pull/11548/files#diff-2f0997968f6094158825cb36c24f8b489c2d3f5aa72279d721077e5901280a30L169 ).

Upon reverting the changed lines in the node_modules of the project, I can execute the build successfully (see example of reverted file below).

After parsing ~8k files Windows has the error ``EMFILE: too many open files` which leads to the build failing. Our project has around 10k files to parse, triggering the error.

The reproduction is basically just creating a blank angular repository, adding tailwindcss, and creating 10'000 blank typescript files.

You can get a Windows VM from https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/

In the VM, the reproduction is as follows: 1) install nodejs and clone (download) the project 2) npm i 3) npm start

With that you can trigger the error.

I think, the async code has either to be disabled on windows (keeping the old sync code), or the async code should work in batches of ~1k files. I could create a PR to disable the async part on Windows, if you'd like.

Example error in console:

HookWebpackError: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
Error: EMFILE: too many open files, open 'C:\git\tailwindowsbugger\src\files\file-919.ts'

expandTailwindAtRules.js in node modules (adapted to fix the bug).

        } else {
            console.log('Reverting the changes...');
            // console.log(_fs.default);
            let count = 0;
            for (let { file, content, extension } of context.changedContent) {
                let transformer = getTransformer(context.tailwindConfig, extension)
                let extractor = getExtractor(context, extension)
                console.log(`File #${count}`, file);
                count++;
                content = file ? _fs.default.readFileSync(file, 'utf8') : content
                getClassCandidates(transformer(content), extractor, candidates, seen)
            }
            await new Promise((resolve, reject) => {
                resolve("foo");
            });

            // await Promise.all(context.changedContent.map(async ({ file , content , extension  })=>{
            //     let transformer = getTransformer(context.tailwindConfig, extension);
            //     let extractor = getExtractor(context, extension);
            //     content = file ? await _fs.default.promises.readFile(file, "utf8") : content;
            //     console.log(`File #${count}`, file);
            //     count++;
            //     getClassCandidates(transformer(content), extractor, candidates, seen);
            // }));
        }
        
@thecrypticace thecrypticace self-assigned this Sep 22, 2023
@thecrypticace
Copy link
Contributor

thecrypticace commented Sep 22, 2023

Yeah I think we'll want to batch file reads into groups rather than turn off the async stuff.

Throwing this here so I don't forget: We can test this super easily on macOS by setting a super low hard file open limit by doing ulimit -Hn 256

(I tested it on Windows too though — I've got a Windows machine I game on)

@thecrypticace
Copy link
Contributor

This should be fixed by #12079, and will be available in the next release.

You can try it by using the insiders build (should be available in ~10m or so once it's built and published):

npm install tailwindcss@insiders

@akehir
Copy link
Author

akehir commented Sep 25, 2023

Cool thanks a lot, I'll try it out tomorrow!

@akehir
Copy link
Author

akehir commented Oct 4, 2023

Can confirm it works with tailwind@insiders in our project, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants