question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

process.env.NODE_DEBUG is undefined

See original GitHub issue

Describe the bug

This may be my misunderstanding of how env variables are processed in Vite but in my project the value process.env.NODE_DEBUG is undefined when compiling a third-party dependency. The dependency in question is @azure/event-hubs.

image

This is not an issue when using another bundler such as webpack, parcel, or rollup.

I have attempted this solution: https://github.com/vitejs/vite/discussions/2344 but I couldn’t get it to work…

Reproduction

I have put together a reproduction of the issue here.

However, for clarity here are the steps:

  1. Create a blank vite project
  2. Add @azure/event-hubs as a dependency
  3. Import anything from @azure/event-hubs

System Info

  System:
    OS: macOS 11.2.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 728.57 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.5 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.11 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 89.1.22.67
    Chrome: 89.0.4389.90
    Edge: 89.0.774.57
    Firefox: 86.0
    Safari: 14.0.3
  npmPackages:
    @vitejs/plugin-vue: ^1.1.5 => 1.1.5 
    vite: ^2.1.2 => 2.1.2 

Used package manager: yarn

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
andrewcourticecommented, Mar 25, 2021

@jacobclevenger Thanks for getting back to me. I’m aware of how to use env variables via import.meta in Vite, unfortunately the issue is that a third-party package references process.env.NODE_DEBUG which is out of my control.

0reactions
wheatjscommented, Mar 26, 2021

This now has a workaround here: https://github.com/Azure/azure-sdk-for-js/issues/14496#issuecomment-808442337

Going to close this as it is an issue with their library and they are working on fixing it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is process.env.NODE_ENV undefined?
process.env is a reference to your environment, so you have to set the variable there. To set an environment variable in Windows: SET...
Read more >
NODE_DEBUG is undefined in bundled env that doesn't ...
The NODE_DEBUG global is undefined when using a bundler such as Vite which doesn't support node shimming. A repo with a reproduction of...
Read more >
ReferenceError: “process is not defined”
In NodeJS, “process” is defined, but not in the browser. This is because NodeJS and the browser are different runtime environments.
Read more >
process.env - process is not defined? : r/reactjs
Hi, `process` is NODE global variable, it is available only during build time of your project - if it is front end project....
Read more >
Working with Environment Variables in Node.js
If you rerun the same command with NODE_ENV set to production, you'll see that it'll stay undefined. NODE_ENV=production node dotenv-example.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found