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

Error: process is not defined #570

Open
harryfino opened this issue Aug 2, 2023 · 2 comments
Open

Error: process is not defined #570

harryfino opened this issue Aug 2, 2023 · 2 comments

Comments

@harryfino
Copy link

I was using version 8.1.0 with no issues. I updated this morning to version 8.1.5 and I started getting this error:
Error: process is not defined

It occurs when I call a feed's get() method.

const client = StreamConnect(API_KEY, accessToken, APP_ID);
const feed = client.feed('feedname', userId);
feed.get({ limit: 0 })
@nusryan
Copy link

nusryan commented Aug 30, 2023

hi @harryfino , unfortunately I'm also facing with this issue, this function works fine locally but I was receiving it when trying to build with Vite

@johnvey
Copy link

johnvey commented Sep 15, 2023

The offending change looks to be here: 8c20f11#diff-25d66d74617fe2e23d7946bd6e3ba95640ab1b9bc8947445d604fc271c7c1f12R399

The code looks like it was written with only server-side Node execution in mind, so any client-side execution that lacks the global process variable will throw this exception.

The workaround for Vite during dev time is to inject a stub in the config file like:

define: {
  'process.env': {}
}

However, that define option changes depending on when you run vite dev vs vite build, so you must use a different workaround for your builds. The simplest workaround is to stub something out in the <head> of your HTML like:

window.process = { env: {} };

If you already have an existing polyfill lib running, you can of course inject it that way.

You can see the equivalent Webpack workaround in the same commit here: 8c20f11#diff-1fb26bc12ac780c7ad7325730ed09fc4c2c3d757c276c3dacc44bfe20faf166fR42

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

3 participants