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

Error when enabling react-scan in webpack production mode

Open XGDumont opened this issue 1 year ago • 5 comments

Hi,

I'm trying to enable react-scan on a staging server using a production build. However, when I enable react-scan, I get the following error:

Do not use scan directly in a Server Component module. It should only be used in a Client Component.

As far as I can tell, the only difference between getting the error and being able to use scan is the switch between using webpack's "development" and "production" modes.

I'm using webpack 5.72.0 and react 17.

Any help would be appreciated! Thank you!

XGDumont avatar Mar 03 '25 18:03 XGDumont

I am seeing this as well in my nextjs app when running the production build.

This error does not show up for npm run dev, but it does show up for npm run build && npm run start.

coltenkrauter avatar Mar 04 '25 23:03 coltenkrauter

Able to reproduce, working on removing the error when it shouldn't show

This error can be ignored in the mean time

RobPruzan avatar Mar 06 '25 22:03 RobPruzan

Thanks for the reply! But actually, the error is blocking and makes it impossible to activate scan. It looks as though the shim is not being replaced properly when building in production mode.

XGDumont avatar Mar 07 '25 14:03 XGDumont

Are there any news? I'm using Next.js 14.2, and I'm also facing this issue although my component is marked as 'use client'.

Yumee-Dev avatar Apr 25 '25 08:04 Yumee-Dev

Are there any news? I'm using Next.js 14.2, and I'm also facing this issue although my component is marked as 'use client'.

Planning on getting a fix out soon (~next release). Haven't had much time to work on the project lately, but have some free time upcoming

RobPruzan avatar Apr 27 '25 02:04 RobPruzan

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