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 is empty since 6.4.10

See original GitHub issue

Describe the bug At runtime, inside of a story, we need access to a (subset of) process.env to pass some values from the buildserver onto Storybook, and ultimately the application proper.

In Storybook 6.4.9 this worked fine. In Storybook 6.4.10 this got broken. process.env is now { }. In Storybook 6.4.14 this is not fixed, unfortunately.

Neither env variables from the CLI are passed, nor variables from .env. We use both, and neither end up in process.env.

Is it possible that #17174 broke this? That one is the only fix that remotely seems to have anything to do with process.env, assuming the changelog is complete.

To Reproduce I’m not sure what has been done to get this to work in the first place, or whether this is standard functionality. I do see dotenv being exported from paths.js, but it’s really difficult to dig into Storybook to see what it’s doing with that, if anything.

System

Environment Info:

  System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  Binaries:
    Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
    npm: 8.3.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 97.0.4692.99
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.62)
  npmPackages:
    @storybook/addon-a11y: 6.4.10 => 6.4.10
    @storybook/addon-actions: 6.4.10 => 6.4.10
    @storybook/addon-controls: 6.4.10 => 6.4.10
    @storybook/addon-docs: 6.4.10 => 6.4.10
    @storybook/addons: 6.4.10 => 6.4.10
    @storybook/preset-create-react-app: 3.2.0 => 3.2.0
    @storybook/react: 6.4.10 => 6.4.10
    @storybook/theming: 6.4.10 => 6.4.10

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:36
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

20reactions
thanycommented, Jan 26, 2022

As a temporary workaround, we can use this in the main.js:

module.exports = {
  webpackFinal: async config => {
    const definePlugin = config.plugins.find(
      ({ constructor }) => constructor && constructor.name === 'DefinePlugin',
    );
    if (definePlugin) {
      definePlugin.definitions = injectEnv(definePlugin.definitions);
    }

    return config;
  },
};

Where injectEnv() looks like this:

function injectEnv(definitions) {
  const env = 'process.env';

  if (!definitions[env]) {
    return {
      ...definitions,
      [env]: JSON.stringify(
        Object.fromEntries(
          Object.entries(definitions)
            .filter(([key]) => key.startsWith(env))
            .map(([key, value]) => [key.substring(env.length + 1), JSON.parse(value)]),
        ),
      ),
    };
  }
  return definitions;
}

Honestly though, I believe #17174 should be reverted, because this is quite a convoluted workaround to something that didn’t need to be broken in the first place. I’m sure it wasn’t intentionally broken, but it sure is a regression, iyam.

9reactions
MagnusHJensencommented, Jul 4, 2022

What is the status on this issue? Makes Storybook unusable, if you want some of the newer features.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Why is process.env returning an empty object, while ...
The issue with process.env variable being empty in browser is because browser doesn't have real access to the process of the node.js ....
Read more >
How To Use Environment Files with env-cmd | DigitalOcean
In this article, you will install and use env-cmd in an example project. Prerequisites. To complete this tutorial, you will need: Node.js ...
Read more >
FortiGate / FortiOS 6.4.10 - Fortinet Documentation Library
Empty application control logs appear in policy-based mode since 7.0.0. DNS Filter. Bug ID. Description. 692482.
Read more >
FortiOS 6.4.10 Release Notes - Amazon AWS
13, SSL VPN web portal users get a blank page after logging in successfully. 809209. SSL VPN process memory leak is causing the...
Read more >
VMware NSX for vSphere 6.4.0 Release Notes
The IPsec VPN uses the VMware Linux Kernel Cryptographic Module (VMware Photon OS 1.0 environment), which is in the process of being CMVP ......
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