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

MaxListenersExceededWarning when having 11+ content scripts defined #1204

Open
5 tasks done
vladgabriel opened this issue Nov 25, 2024 · 2 comments · May be fixed by #1207
Open
5 tasks done

MaxListenersExceededWarning when having 11+ content scripts defined #1204

vladgabriel opened this issue Nov 25, 2024 · 2 comments · May be fixed by #1207
Assignees
Labels
bug Something isn't working
Milestone

Comments

@vladgabriel
Copy link

Describe the bug

When adding over 11 content scripts the following error is displayed:

(node:38511) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit

Reproduction

memory-setup.zip

Steps to reproduce

Run yarn install and yarn dev

System Info

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 76.14 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - ~/.asdf/installs/nodejs/20.15.1/bin/node
    Yarn: 4.5.0 - ~/.asdf/installs/nodejs/20.15.1/bin/yarn
    npm: 10.7.0 - ~/.asdf/plugins/nodejs/shims/npm
    bun: 1.0.26 - ~/.bun/bin/bun
  Browsers:
    Chrome: 131.0.6778.86
    Chrome Canary: 133.0.6858.0
    Safari: 17.2.1

Used Package Manager

yarn

Validations

@vladgabriel vladgabriel added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Nov 25, 2024
@aklinker1
Copy link
Collaborator

aklinker1 commented Nov 25, 2024

I've noticed this as well, seems like each entrypoint group (build step) adds a listener... I assume because vite is adding it? Not 100% sure which dependency is causing it, but vite is my best guess.

This only happens on node 20 and up.

@aklinker1 aklinker1 added bug Something isn't working and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Nov 25, 2024
@aklinker1
Copy link
Collaborator

aklinker1 commented Nov 25, 2024

This is caused by:

const defaultExport =
await wxt.builder.importEntrypoint<ContentScriptDefinition>(inputPath);

Specifically when importing multiple entrypoints to extract their options during the build process, like content script matches, we use vite-node to import the TS file and do some preprocessing to speed things up.

However, for every imported entrypoint, we have to create a Vite dev server, and that's where the warning comes from, the dev server setting up a listener to close the server when stopping the process.

Fix is simple, only create a single dev server when importing entrypoint files, but refactoring the code to support that won't be... An easier fix is to import the files one by one, not in parallel, or setup a queue that only allows 9 imports be running at a time.

But I'd rather refactor and get this done right. For now, you can ignore this warning. It shouldn't be causing any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants