(Created on )

Puppeteer: A disposed stack can not use anything new

A DisposableStack has already been disposed or moved, so it cannot accept new resources.


A DisposableStack has already been disposed or moved, so it cannot accept new resources.

Error message

A disposed stack can not use anything new

How this error happens

A disposable stack cannot accept cleanup work after disposal or after its resources have been moved to another stack. Reusing it crosses its resource-ownership boundary.

const stack = new DisposableStack();

stack.dispose();

stack.defer(() => {
    console.log("Cleanup");
});

How to fix

Register resources before disposal, and create a new stack for a new scope.

const stack = new DisposableStack();

try {
    stack.defer(() => {
        console.log("Cleanup");
    });

    console.log("Work");
} finally {
    stack.dispose();
}

Things to keep in mind

The code demonstrates the lifecycle through JavaScript’s public DisposableStack where that runtime API is available. Native error wording can differ from Puppeteer’s internal stack message. Do not reach into Puppeteer’s private cleanup stack.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →