The "useId is not available in this React build" error occurs when trying to use the React 18 useId hook with an older version of React or an incompatible build configuration. useId is a React 18+ feature for generating unique IDs across server and client renders, and this error indicates your React version or build setup does not support this hook. Upgrading React or adjusting your build configuration resolves this issue.
The useId hook is a React feature introduced in React 18 for generating stable, unique identifiers that are consistent between server-side rendering (SSR) and client-side hydration. This error message appears when your application attempts to call useId() but the React library being used either predates React 18 or was built without this feature enabled. This can happen when using an older React version (17 or earlier), when using a custom React build that excludes certain features, or when there's a mismatch between development and production builds. The error prevents your component from rendering because React cannot find the useId implementation in the current build.
Verify that you have React 18 or newer installed. Check your package.json file and look for the react and react-dom dependencies. Both should be version 18.0.0 or higher.
# Check installed versions
npm list react react-dom
# or
yarn list react react-dom
# Expected output should show version 18.x.x or higher
[email protected]
[email protected]
# If versions are lower, upgrade:
npm install react@latest react-dom@latest
# or
yarn add react@latest react-dom@latestReact and react-dom must be the same major version. A mismatch (e.g., react@18 with react-dom@17) causes this error. Check both packages and update if necessary.
// package.json - ensure versions match
{
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0" // Must match react version
}
}
// If versions don't match, update:
npm install react-dom@18
# or remove node_modules and package-lock.json, then reinstall
rm -rf node_modules package-lock.json
npm installPackage manager caches can sometimes serve old or corrupted versions. Clear the cache and reinstall dependencies to ensure you get the correct React version.
# For npm
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
# For yarn
yarn cache clean
rm -rf node_modules yarn.lock
yarn install
# For pnpm
pnpm store prune
rm -rf node_modules pnpm-lock.yaml
pnpm installMultiple React versions can cause conflicts. Check if React is installed multiple times in your dependency tree.
# Check for duplicate React installations
npm ls react
# Look for lines like:
# ├─┬ [email protected]
# └─┬ [email protected]
# └── [email protected] # DUPLICATE - problem!
# Use resolutions in package.json to force single version (yarn/pnpm)
{
"resolutions": {
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
# For npm, use overrides
{
"overrides": {
"react": "18.2.0",
"react-dom": "18.2.0"
}
}If you're using a custom React build (e.g., for bundle optimization), ensure it includes the useId feature. Check your bundler configuration (Webpack, Vite, etc.) for any custom React imports or aliases.
// Webpack example - ensure you're not aliasing to an older React
// webpack.config.js
module.exports = {
resolve: {
alias: {
// WRONG - points to custom build without useId
react: path.resolve(__dirname, 'custom-react/build.js'),
// CORRECT - use standard React
// Remove or update this alias
}
}
};
// Vite example
// vite.config.js
export default {
resolve: {
alias: {
// Check for problematic aliases
'react': 'preact/compat' // This would cause the error
}
}
};Create a minimal test case to isolate the issue. This helps determine if the problem is in your project configuration or dependencies.
// Minimal test component
import { useId } from 'react';
export function TestComponent() {
const id = useId();
return <div id={id}>Test</div>;
}
// Create a simple app to test
import { createRoot } from 'react-dom/client';
import { TestComponent } from './TestComponent';
const root = createRoot(document.getElementById('root'));
root.render(<TestComponent />);
// If this works, the issue is elsewhere in your project
// If it fails, the React installation is the problemIf you cannot upgrade to React 18, consider alternative approaches for generating unique IDs.
// Alternative 1: Use a counter (client-side only)
let idCounter = 0;
export function useClientId() {
const [id] = useState(() => `id-${idCounter++}`);
return id;
}
// Alternative 2: Use nanoid or uuid for random IDs
import { nanoid } from 'nanoid';
export function useRandomId() {
const [id] = useState(() => nanoid());
return id;
}
// Alternative 3: Use ref with useEffect (SSR compatible)
export function useStableId() {
const [id, setId] = useState<string | null>(null);
useEffect(() => {
if (!id) {
setId(`id-${Math.random().toString(36).slice(2)}`);
}
}, [id]);
return id || 'loading';
}
// Note: These alternatives may not be SSR-safe like useIdThe useId hook was introduced in React 18 as part of the concurrent features set. It generates stable IDs that work correctly with server-side rendering by using a deterministic algorithm based on the component tree position. This is different from random ID generators which can cause hydration mismatches in SSR. If you're using Next.js, ensure you're on version 12 or higher which supports React 18. Some build tools like Create React App may need to be updated to version 5+ for React 18 support. If you encounter this error in a monorepo, check that all packages use the same React version by using workspaces with hoisted dependencies. For library authors, consider making useId optional with a fallback for older React versions using feature detection.
React Hook useCallback has a missing dependency: 'variable'. Either include it or remove the dependency array react-hooks/exhaustive-deps
React Hook useCallback has a missing dependency
Cannot use private fields in class components without TS support
Cannot use private fields in class components without TS support
Cannot destructure property 'xxx' of 'undefined'
Cannot destructure property of undefined when accessing props
useNavigate() may be used only in the context of a <Router> component.
useNavigate() may be used only in the context of a Router component
Cannot find module or its corresponding type declarations
How to fix "Cannot find module or type declarations" in Vite