This rule disallows the use of unsupported Node API calls within components that may run during server-side rendering. These APIs are not available in client-side rendering environments and can lead to serious issues when used without proper safeguards. To avoid unexpected behavior and security vulnerabilities, certain problematic Node APIs should not be used in SSR contexts.
The following Node APIs are disallowed in SSR contexts:
require
fs
child_process
worker_threads
perf_hooks
The purpose of this rule is to prevent the use of dangerous Node API calls in SSR contexts. If you must perform these operations, ensure they are only executed in environments where they are supported.
const fs = require('fs');
if (import.meta.env.SSR) {
// unsupported Node API call within SSR context
fs.writeFileSync('file.txt', 'data');
}
// Do not use Node APIs