Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing as ES module, DevTool is included in production build #175

Open
jpa00 opened this issue Sep 8, 2022 · 7 comments
Open

Importing as ES module, DevTool is included in production build #175

jpa00 opened this issue Sep 8, 2022 · 7 comments

Comments

@jpa00
Copy link

jpa00 commented Sep 8, 2022

As the title says, when a project by default imports and builds everything from ES modules, hookform's DevTool import returns the entire code even in production builds, instead of the noop of the default import.

Depending on the environment, a quick workaround may be to import from /dist/index for now, which returns either the CommonJS-version or a noop DevTool.

@AdiRishi
Copy link

AdiRishi commented Oct 23, 2022

+1 I just came across this as well (building a React app with Vite)

Made a quick demo to showcase the problem - https://stackblitz.com/edit/github-ei8jpp?file=src/Home/index.tsx

@steveoh
Copy link

steveoh commented Nov 2, 2022

Is this going to be addressed or should we use the work around?

steveoh added a commit to agrc/plss that referenced this issue Nov 2, 2022
this isn't removed in production builds

refs react-hook-form/devtools#175
@AdiRishi
Copy link

Any updates on this issue?

@timsofteng
Copy link

timsofteng commented May 30, 2023

+1
@bluebill1049 may you take a look at this issue please?

@burnedikt
Copy link

A workaround (that could turn into a solution) inspired by react-query-devtools that worked for me is to create the following file and always import the DevTool from there:

hookform-devtools.ts

import * as hookFormDevTools from "@hookform/devtools";

export const DevTool: (typeof hookFormDevTools)["DevTool"] =
  process.env.NODE_ENV !== "development"
    ? function () {
        return null;
      }
    : hookFormDevTools.DevTool;

then change your import from

- import { DevTool } from "@hookform/devtools";
+ import { DevTool } from "../hookform-devtools";

@hadson172
Copy link

+1 any updates?

@RomainMorlevat
Copy link

RomainMorlevat commented Jan 5, 2024

My workaround:
{import.meta.env.VITE_RHF_DEVTOOLS && <DevTool control={control} />}

edit: it's not working 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants