Skip to content

process.env not polyfilled for Edge Functions in CLI #1864

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

Closed
hrishikesh-k opened this issue Jan 4, 2023 · 1 comment · Fixed by #1889
Closed

process.env not polyfilled for Edge Functions in CLI #1864

hrishikesh-k opened this issue Jan 4, 2023 · 1 comment · Fixed by #1889
Assignees
Labels
good first issue Good for newcomers priority: medium type: bug code to address defects in shipped code

Comments

@hrishikesh-k
Copy link

Describe the bug

This report is coming from a user here: https://answers.netlify.com/t/82464

They're trying to use environment variables in their Next.js code using process.env which is native to any Next.js developer. Since the middleware is running on Edge Functions (in production as well as in CLI), the correct syntax is Deno.env instead of process.env. In our production environment, we polyfill this, so users can get a seamless experience. However, it appears that the polyfill is missing in CLI.

Steps to reproduce

There's a code example in the thread above, which can cause this issue.

Configuration

No response

Environment

Sharing my system details, but should happen on any system (with current latest version of CLI - v12.5.0):

System:
    OS: macOS 13.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 504.87 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.asdf/installs/nodejs/18.12.1/bin/node
    npm: 9.2.0 - ~/.asdf/plugins/nodejs/shims/npm
@hrishikesh-k hrishikesh-k added the type: bug code to address defects in shipped code label Jan 4, 2023
@ascorbic ascorbic transferred this issue from netlify/cli Jan 4, 2023
@ascorbic
Copy link
Contributor

ascorbic commented Jan 4, 2023

We need to add the polyfill to the next-dev edge function. It's already included in production, but it's missing from dev. We need to add something like:

globalThis.process ||= { env: Deno.env.toObject() }

...into this edge function: https://github.com/netlify/next-runtime/blob/main/packages/runtime/src/templates/edge/next-dev.js

As a workaround until the fix lands, a user could add that to their own middleware function.

@ascorbic ascorbic added the good first issue Good for newcomers label Jan 4, 2023
@sarahetter sarahetter removed their assignment Jan 18, 2023
@kodiakhq kodiakhq bot closed this as completed in #1889 Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers priority: medium type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants