ESLint plugin that detects incorrect use of DOM globals (e.g., window, document, navigator) in module scope, constructors, React component render methods, and function components, ensuring code is safe for server-side rendering (SSR) and Node.js environments. Stable version 1.3.0 as of August 2023. It focuses on preventing runtime errors during SSR by catching patterns that assume a browser environment. Unlike general linting rules, it provides specific rules for React class components, function components, and class constructors. Released under MIT license with monthly releases.
npm install eslint-plugin-ssr-friendlyVerified import paths — ran on the pinned version, not inferred.
Quick setup using recommended config; shows how to enable all rules and example violations.
Manually review code that accesses DOM globals through functions or variables.
Ensure all uses of DOM globals in functions are guarded with 'if (typeof window !== "undefined")'.
Specify exact version in package.json (e.g., "eslint-plugin-ssr-friendly": "1.3.0") and review changelog before upgrading.
Ensure 'eslint-plugin-ssr-friendly' is installed and added to plugins: ['ssr-friendly'].
Run 'npm install --save-dev eslint-plugin-ssr-friendly'.