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.

Using Environmental Variables

See original GitHub issue

Do you want to request a feature or report a bug? Bug

What is the current behaviour? Using dotenv, expose some environmental variables with a snippet in preact.config.js (below), additional environmental variables should be available via process.env.

Process is undefined.

If the current behaviour is a bug, please provide the steps to reproduce.

const { plugin } = helpers.getPluginsByName(config, 'DefinePlugin')[0];
const { parsed } = require('dotenv').config();
Object.assign(
  plugin.definitions,
  Object.keys(parsed).reduce(
    (env, key) => ({
      ...env,
      [`process.env.${key}`]: JSON.stringify(parsed[key]),
    }),
    {}
  )
);

package.json dependencies:

{
"devDependencies": {
        "@types/dompurify": "0.0.33",
        "@types/jest": "^23.3.10",
        "@types/node": "^12.7.5",
        "@types/prismjs": "^1.16.0",
        "@types/webpack-env": "^1.13.9",
        "css-loader": "^1.0.1",
        "dotenv": "^8.1.0",
        "husky": "^1.2.0",
        "identity-obj-proxy": "^3.0.0",
        "jest": "^23.6.0",
        "jest-preset-preact": "^1.0.0",
        "lint-staged": "^8.1.0",
        "per-env": "^1.0.2",
        "preact-cli": "^3.0.0-next.19",
        "prettier": "^1.15.3",
        "ts-jest": "^23.10.5",
        "ts-loader": "^3.5.0",
        "tslint": "^5.11.0",
        "tslint-config-prettier": "^1.17.0",
        "tslint-consistent-codestyle": "^1.14.1",
        "tslint-eslint-rules": "^5.4.0",
        "tslint-react": "^3.6.0",
        "typescript": "^3.2.1",
        "typings-for-css-modules-loader": "^1.7.0",
        "webpack": "^4.28.4"
    },
    "dependencies": {
        "@fortawesome/fontawesome-svg-core": "^1.2.22",
        "@fortawesome/free-regular-svg-icons": "^5.10.2",
        "@fortawesome/free-solid-svg-icons": "^5.10.2",
        "@fortawesome/react-fontawesome": "^0.1.4",
        "bootstrap": "^4.3.1",
        "dompurify": "^1.0.11",
        "marked": "^0.7.0",
        "preact": "^10.0.0-rc.1",
        "preact-render-to-string": "^5.0.6",
        "preact-router": "^3.0.1",
        "prismjs": "^1.17.1",
        "reactstrap": "^8.0.1",
        "webfontloader": "^1.6.28"
    }
}

What is the expected behaviour?

process.env.VARIABLE_NAME should be available

If this is a feature request, what is motivation or use case for changing the behaviour?

Please mention other relevant information.

Please paste the results of preact info here.

        β–„β–„
     β–„β–„β–“β–“β–“β–“β–“β–“β–„β–„
  β–„β–ˆβ–€β–€β–ˆβ–“β–“β–“β–“β–“β–“β–“β–€β–€β–ˆβ–„β–„
β–β–“β–Œβ–β–“β–“β–“β–’β–„ β–€β–„β–„β–“β–“β–“β–Œβ–β–“β–Œ
▐▓▓▄▀▓▀ β–„β–“β–“β–„β–„β–€β–“β–“ β–“β–“β–Œ
β–β–“β–“β–“β–Œ β–’β–“β–Œ  ▐▓▓  β–“β–“β–“β–Œ preact-cli 2.2.1
▐▓▓ β–’β–“β–„β–„β–€β–“β–“β–€ β–„β–“β–“ β–“β–“β–Œ
β–β–“β–Œβ–β–“β–“β–“β–€β–€β–„β–„β–€β–€β–“β–“β–“β–Œβ–β–“β–Œ
  β–€β–ˆβ–„β–„β–’β–“β–“β–“β–“β–“β–“β–’β–„β–„β–’β–€
      β–€β–“β–“β–“β–“β–“β–“β–€β–€
         β–€β–€

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bojan88commented, Sep 29, 2019

@UbiquitousBear I tried to reproduce the issue, but it seems like everything is working as expected.

I see that your package.json has one version, and you have another global version of preact-cli module. Maybe that can be the cause of your problems.

I tried exposing variables from .env file using both 3.0.0-next.19 and 3.0.0-rc.5, and everything looks fine.

0reactions
ForsakenHarmonycommented, Mar 6, 2021

I’ll close this for now, given that it’s workingβ„’

Read more comments on GitHub >

github_iconTop Results From Across the Web

An Introduction to Environment Variables and How to Use Them
An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system orΒ ...
Read more >
What Are Environment Variables and How Can I Use Them ...
Environment variables are predetermined values that are typically used to provide the ability to configure a value in your code from outside ofΒ ......
Read more >
Environment Variables: What They Are and How To Use Them
Environment Type: Environment variables are often used to store the name of the environment in which the app is currently running. The app'sΒ ......
Read more >
Create and Modify Environment Variables on Windows
Create and Modify Environment Variables on Windows Β· On the Windows taskbar, right-click the Windows icon and select System. Β· In the Settings...
Read more >
Environment variable - Wikipedia
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of...
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