form-atoms / form-atoms

Atomic form primitives for Jotai

Home Page:https://codesandbox.io/s/getting-started-with-form-atoms-v2-ddhgq2?file=/src/App.tsx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Debug label not set in vite

schiller-manuel opened this issue · comments

In vite, process is not defined (though process.env.NODE_ENV is working) and thus thetypeof process !== "undefined" check fails in

https://github.com/jaredLunde/form-atoms/blob/727c25073a912188251ace8bc2f08dbfae84188a/src/index.tsx#L372C7-L372C37

https://github.com/jaredLunde/form-atoms/blob/727c25073a912188251ace8bc2f08dbfae84188a/src/index.tsx#L714C7-L714C37

So in the Jotai DevTools, all form/field atoms are unlabeled:
Screenshot 2023-10-15 at 22 36 53

As a quick fix you can update your vite config:

import { defineConfig } from 'vite'
// ...
export default defineConfig({
  // ...
  define: {
    'process.env': {}
  }
})

But maybe we should update the check to use the import.meta.env.MODE instead
https://vitejs.dev/guide/env-and-mode.html

Thanks for the workaround!

But maybe we should update the check to use the import.meta.env.MODE instead https://vitejs.dev/guide/env-and-mode.html

This would then only work in vite... which is fine for but maybe not for other users of this library :D

I'm not willing to create a special check for every bundler that pops up in node. The process check is fairly standard in node libraries including React.