brysgo / babel-plugin-inline-dotenv

Load your .env file and replace 'process.env.MY_VARIABLE' with the value you set.
124 stars 13 forks source link

weird issue #112

Closed antoinerousseau closed 4 years ago

antoinerousseau commented 4 years ago

I'm using this plugin for my typescript lambda functions. So, in my functions folder, I have a .babelrc with:

{
  "presets": [
    "@babel/preset-typescript",
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "10.19"
        }
      }
    ]
  ],
  "plugins": [
    "inline-dotenv",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-transform-object-assign",
    "@babel/plugin-proposal-object-rest-spread"
  ]
}

And I have a .env in the root folder (from where the lambda is started, using netlify-lambda serve src/functions)

But in my TS lambda file, my process.env.SOME_VAR variables don't get properly replaced, instead they get process && process.env && process.env.SOME_VAR || undefined. But if somewhere I add a console.log(process.env.SOME_VAR), it fixes them all! It also fixes the issue if I replace "inline-dotenv" with ["inline-dotenv", {}] in .babelrc... Note that BABEL_DISABLE_CACHE=1 does not help.

antoinerousseau commented 4 years ago

Ok I had to clear babel's cache as per https://github.com/brysgo/babel-plugin-inline-dotenv/issues/7#issuecomment-343300281 :/