Skip to content

Fix chromatic check when process undefined (e.g. vite project) #8494

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neofight78
Copy link

In a freshly created vite project dialogs fail to open with this error:

Uncaught ReferenceError: process is not defined
$bc765a7a041310da$export$b847a40ee92eff38 OpenTransition.tsx:40

In a vite project process is not defined and causes a check for chromatic to fail.

This PR fixes this.

@neofight78 neofight78 force-pushed the fix-dialog-open-for-vite branch from 24a2f37 to 8627def Compare July 6, 2025 11:05
@snowystinger
Copy link
Member

Thanks for the PR. Have you followed this discussion first? #8189

@neofight78
Copy link
Author

I did try to search open issues but didn't find anything. I missed that discussion, although I did see somewhere the define workaround for code that uses process. It seemed to me better just to make it work out of the box though, otherwise people will keep tripping up over it.

@snowystinger
Copy link
Member

Yes, I'd like it to just work as well. This PR wouldn't fix all the instances of it though. I think it'd be good to determine how it works for React, as pointed out in that discussion, and use that approach so it's consistent.

@neofight78
Copy link
Author

Where else are you seeing problems? This PR fixes the issue in the linked discussion too. As far as I can see other instances of accessing process use process.env.NODE_ENV which is automatically substituted by vite (this is not react specific functionality). For instance if I add this code, I get a message logged as expected:

image

Other env vars look like they are accessed only in test?

@snowystinger
Copy link
Member

Ah, I see, process.env.NODE_ENV is super special to bundlers, that's annoying.

I had at one point tried to solve this with https://parceljs.org/features/node-emulation/#disabling-these-features since we don't really want these code paths to end up in our bundles for process.env.CHROMATIC

but we DO eventually want process.env.VIRT_ON, so that people can use that for testing virtualisation more easily. It'd currently be a possible issue if you're using NODE_ENV===test. If you only use "production", then not a problem.

I'm ok with putting it behind typeof process !== 'undefined' for now but we really need to be removing this code for production

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

Successfully merging this pull request may close these issues.

2 participants