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

Uncaught ReferenceError: process is not defined #113

Closed
Penkie opened this issue Jan 4, 2021 · 21 comments
Closed

Uncaught ReferenceError: process is not defined #113

Penkie opened this issue Jan 4, 2021 · 21 comments
Labels
bug Something isn't working released

Comments

@Penkie
Copy link

Penkie commented Jan 4, 2021

Bug report

Describe the bug

Using Angular, creating the client produce this error on the console: Uncaught ReferenceError: process is not defined

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create Angular project
  2. Install supabase-js
  3. Create angular service
  4. Import createClient with supabase-js on top of the newly created service
  5. Add that on top of the file, after the import const supabase = createClient('yoururl', 'yourkey')
  6. Link service to component
  7. See result in console

Expected behavior

No errors should happen

System information

  • OS: MacOS Big Sur
  • Browser (if applies) Firefox
  • Version of supabase-js: v1.1.3
  • Version of Node.js: v12.18.3
@Penkie Penkie added the bug Something isn't working label Jan 4, 2021
@emschwartz
Copy link

I think this may have been fixed by supabase/auth-js#37 What version of gotrue-js is it pulling in?

@kiwicopple
Copy link
Member

🎉 This issue has been resolved in version 1.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Penkie
Copy link
Author

Penkie commented Jan 6, 2021

I updated supabase-js to 1.1.4 and checked that gotrue-js is 1.9.3 (wich is the case) and I'm still having this issue

@kiwicopple kiwicopple reopened this Jan 6, 2021
@kiwicopple
Copy link
Member

OK thanks for the update @Penkie . Reopening to investigate ..

@kiwicopple
Copy link
Member

kiwicopple commented Jan 6, 2021

  1. Create Angular project
  2. Create angular service

Could you please set this up on codesandbox or give some instructions? I've never used angular, this would probably take me an hour to figure out. Even better if you can start ad branch with anangular-todo-list in our examples. That would be massively helpful for the community (but not necessary, I just need a way to debug this)

@Penkie
Copy link
Author

Penkie commented Jan 6, 2021

I tried with stackblitz, no problem I didn't have any errors. Tried also on codesandbox, loads of problems, maybe the dependencies not working. Anyway I created a repo with the Angular project inside : https://github.com/Penkie/supabase-js-debug-angular
You can check there
Note that I did not create any service (like I mentionned up there that you have to, but actually no you don't), so everything is on app.component.ts

@laurentS
Copy link

For what it's worth, I'm having the same issue in a svelte/sapper app. For now, I'm bypassing the error with window.process = window.process || null in the page's script. It's not exactly ideal, but for now I can move on :)

I've setup a basic repro repo at https://github.com/laurentS/supabase-bug-repro-113
to reproduce:

  • clone the repo
  • yarn install
  • yarn run dev
  • open the landing page (should be http://localhost:3000) and watch the error message appear after a few milliseconds

All it takes is importing the supabase client (see the last commit in the main branch).
Hope this helps!

@soedirgo
Copy link
Member

Looks like gotrue-js is using process.env, which makes it non-isomorphic. supabase/auth-js#37 moves the problem to the bundler (Rollup) instead, which wasn't able to match-replace process.env. So if you add "process": undefined in the Rollup replace plugin in laurentS's example above, the app works.

Can we maybe refactor gotrue-js to use e.g. default parameters when initializing the client instead?

@inian
Copy link
Member

inian commented Jan 12, 2021

Error report from @thorwebdev
our unpkg build (https://unpkg.com/@supabase/supabase-js@1.1.4/dist/umd/supabase.js) is erroring
image

@kiwicopple
Copy link
Member

Hey @soedirgo - just checking on this commit

particularly these lines:

    new webpack.DefinePlugin({
      'process.env.GOTRUE_URL': undefined,
      'process.env.AUDIENCE': undefined,
      'process.env.EXPIRY_MARGIN': undefined,
      'process.env.STORAGE_KEY': undefined,
    }),

Is there a webpack plugin that can fix this issue for browser builds? Maybe this?

@soedirgo
Copy link
Member

Huh, I don't remember adding those... let me try that.

@soedirgo
Copy link
Member

soedirgo commented Jan 13, 2021

Hey @Penkie, can you update the supabase-js client and see if it works now? I tried @laurentS's Sapper app with the update and saw no issue.

Edit: my bad, it's still not working. Give me a moment.

@soedirgo
Copy link
Member

So using the Webpack plugin above wouldn't fix it, because it only affects the browser build that's in dist/umd. So the change needs to be in the user's bundler config.

@kiwicopple is there a specific reason to use process.env in gotrue-js? Looks like it's only used as default options for the client. Otherwise I can make a quick PR to fix this.

@kiwicopple
Copy link
Member

is there a specific reason to use process.env in gotrue-js

That was just as a convenience, but looks like it's problematic. How are these usually handled in isomorphic libs? Using dotenv?

@soedirgo
Copy link
Member

I don't think libraries in general use process.env, only apps. Maybe it's possible to use Webpack for all 3 builds, but that's an antipattern (bundling should be done by end-user apps, not libraries), and more trouble than it's worth, IMO.

@jhoch
Copy link

jhoch commented Jan 20, 2021

For another data point, I was running into a similar issue, and applied the fix you put up in supabase/auth-js#42 locally, and it resolved the issue.

@kiwicopple
Copy link
Member

OK , just pushing the new version - I'll keep it open this time until we've confirmed that it's resolved

@kiwicopple kiwicopple reopened this Jan 20, 2021
@kiwicopple
Copy link
Member

🎉 This issue has been resolved in version 1.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@soedirgo
Copy link
Member

Should be working now, when trying laurentS's example above make sure to yarn upgrade first. Let us know if it works for y'all!

@malobre
Copy link

malobre commented Jan 20, 2021

Updating to 1.3.2 did fix the problem for me.

@kiwicopple
Copy link
Member

thanks for the patience everyone! We're super busy, so a bit slow getting to some of these items. I'll close this, and feel free to reopen if you have any issues

And thanks for checking out Supabase ⚡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

8 participants