Error in production mode [React, Vite]
After build (npm run build, npm run start) and in production (npm run build, serve index.js) I have an error and React Scan doesnt run:
Do not use scan directly in a Server Component module. It should only be used in a Client Component.
Usage:
// index.ts
scan({
enabled: shouldEnableReactScan(), // check env, its correct
});
renderApp(); // there is React
Dependencies:
"react": "^19.0.0"
"vite": "^6.1.0"
"react-scan": "0.1.4"
I am running into the same issue, loading react-scan from main.tsx with Vite:
scan({
enabled: process.env.NODE_ENV === 'development',
})
Able to reproduce, will try to get a fix out soon
If you are using vite, as a temporary measure you can add @react-scan/vite-plugin-react-scan to your vite config.
import reactScan from "@react-scan/vite-plugin-react-scan";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
reactScan({ enable: true }),
],
css: { transformer: "lightningcss" },
});
I am running into the same issue, loading
react-scanfrommain.tsxwith Vite:scan({ enabled: process.env.NODE_ENV === 'development', })
isn't vite supposed to expose env vars like this?
scan({
enabled: import.meta.env.MODE === "development",
});
I'm using it this way without any issue
I also have the same problem. Can't figure out a way to run it in production with Next.js App Router.
This error is no longer present in [email protected]
If you want to run react-scan in production you can use the following:
import {scan} from 'react-scan/all-environments'
scan() // <- works in production and dev