(Created on )

Puppeteer: fs is not available in this environment

A filesystem API is used in an environment without Node filesystem dependencies.


A filesystem API is used in an environment without Node filesystem dependencies.

Error message

fs is not available in this environment

How this error happens

Puppeteer’s browser-only build cannot write to a Node.js filesystem. Giving a screenshot a local path asks for a filesystem capability that runtime does not have.

The snippets use a page connected through Puppeteer’s browser-only build.

await page.screenshot({
    path: "/absolute/path/screenshot.png",
});

How to fix

Omit the local path when you need the image bytes in a non-Node environment, or perform file output in a supported Node.js process.

const image = await page.screenshot({
    type: "png",
});

console.log(image.byteLength);

Things to keep in mind

Depending on the build, missing filesystem support can be reported as fs, writeFile or another environment dependency. Returning bytes is not the same as saving a file.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →