Skip to content

Cannot reliably read process.env #1504

@chenyan-dfinity

Description

@chenyan-dfinity

Describe the bug

I'm running webpack 5 inside the web container, and passed in environment variable MYFLAG. The source code uses process.env.MYFLAG to read the environment variable. In webpack.config.js, I can correctly read the MYFLAG value. But in src/index.js, process.env.MYFLAG is sometimes undefined, and sometimes the correct value. The result of process.env.MYFLAG in the bundled code is unpredictable. I tried to read pre-defined variables like process.env.HOME, the result is the same.

Link to the blitz that caused the error

https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-fapmje?file=files.js

Steps to reproduce

  1. Go to the stackblitz link
  2. See the preview window and console log.
  3. During running webpack, MYFLAG is correctly printed to console log.
  4. The preview window on the right shows: "flag: undefined", which should be "flag: PASSED_IN_FLAG"
  5. Rerun this at different times, the preview window can sometimes show the expected result.

Expected behavior

webpack should read process.env reliably for bundled code

Parity with Local

Screenshots

No response

Platform

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions