"ReferenceError: $RefreshReg$ is not defined" when using React + Yarn Workspaces

See original GitHub issue

Describe the bug

I encountered this problem in our Yarn Workspaces setup, where a shared design-system package uses Vanilla Extract to house token values, it creates a theme, and also contains shared React components. These are all exported through a barrel index.ts file.

We have two React apps that import from this - a Create React App and a Next App. Both apps encounter this error during compilation when importing from design-system in development mode. The CRA app can ‘bypass’ it by disabling Fast Refresh altogether, but this isn’t an option for Next.

In my testing, I believe this error only occurs when a React component is exported alongside the Vanilla Extract createTheme in a separate workspace package. In testing I was able to createTheme in a standalone package and import and use it successfully in the Next app package. And I was able to export standalone React components with applied Vanilla Extract style() without issue. Only when using React components and createTheme in the same package did I encounter this issue.

error - ./pages/home.css.ts
NonErrorEmittedError: (Emitted value instead of an instance of Error) ReferenceError: $RefreshReg$ is not defined

Any ideas what might be causing this?

Link to reproduction

I created a simple repo to reproduce: https://github.com/Jpoliachik/ve-workspace-react-issue

System Info

Output of npx envinfo --system --npmPackages @vanilla-extract/css,@vanilla-extract/webpack-plugin,@vanilla-extract/esbuild-plugin,@vanilla-extract/vite-plugin,@vanilla-extract/sprinkles,webpack,esbuild,vite --binaries --browsers:

  System:
    OS: macOS 12.2
    CPU: (8) arm64 Apple M1
    Memory: 658.64 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 3.2.0 - ~/.nvm/versions/node/v16.14.0/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  Browsers:
    Chrome: 101.0.4951.54
    Safari: 15.3

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

9reactions
JCMaiscommented, Jun 21, 2022

Having the same issue, is having a separate build step the only solution?

1reaction
alexchantasticcommented, Aug 30, 2022

@imbhargav5 thank you! That worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug Report: "ReferenceError: $RefreshReg$ is not defined ...
Description I'm upgrading a local plugin + Backstage app to 1.7, and started seeing the following error when I run yarn workspace backend...
Read more >
ReferenceError: $RefreshReg$ is not defined - Stack Overflow
In my case, this error was happening when overwriting Webpack's mode option. After removing the line below I stopped receiving the error.
Read more >
react-refresh-webpack-plugin - Bountysource
So I use your plugin but $RefreshReg$ is not defined error occurred. I follow your Troubleshooting, but none of the solutions work for...
Read more >
@pmmmwh/react-refresh-webpack-plugin - Package Manager
An EXPERIMENTAL Webpack plugin to enable "Fast Refresh" (also known as Hot Reloading) for React components. This plugin is not 100% stable.
Read more >
[Solved]-ReferenceError: $RefreshReg$ is not defined-Reactjs
I've also stumbled on this issue on a CRA project. I'm not using typescript for the Web Worker but adding this helped fix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found