react-scan icon indicating copy to clipboard operation
react-scan copied to clipboard

Error in production mode [React, Vite]

Open ervnkv opened this issue 11 months ago • 5 comments

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"

Image

ervnkv avatar Mar 21 '25 12:03 ervnkv

I am running into the same issue, loading react-scan from main.tsx with Vite:

scan({
  enabled: process.env.NODE_ENV === 'development',
})

bdevos avatar Mar 27 '25 07:03 bdevos

Able to reproduce, will try to get a fix out soon

RobPruzan avatar Mar 28 '25 18:03 RobPruzan

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" },
});

Image

Curstantine avatar Apr 13 '25 06:04 Curstantine

I am running into the same issue, loading react-scan from main.tsx with 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

rluncasu avatar Apr 28 '25 21:04 rluncasu

I also have the same problem. Can't figure out a way to run it in production with Next.js App Router.

perfectbase avatar May 07 '25 02:05 perfectbase

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

RobPruzan avatar Jun 29 '25 00:06 RobPruzan