Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to inject environment variables #1093

Closed
sahibjotsaggu opened this issue May 24, 2024 · 3 comments
Closed

Not able to inject environment variables #1093

sahibjotsaggu opened this issue May 24, 2024 · 3 comments

Comments

@sahibjotsaggu
Copy link

Couldn't find anything in the documentation but after learning that something like

execa`MY_ENV=testing echo $MY_ENV`

won't work, I saw that we can use the Options argument to define environment variables.

However, trying the following did not work as expected:

const { stdout } = await execa({
  extendEnv: true,
  env: {
    $MY_ENV: "test",
  },
})`echo $MY_ENV`;
console.log(stdout); // $MY_ENV instead of test

Here's the sandbox

@ehmicky
Copy link
Collaborator

ehmicky commented May 24, 2024

Hi @sahibjotsaggu,

Thanks for reaching out. The answer to your question is in #1081 (and in the documentation links mentioned in that issue).

As a side note, please note that the environment variable names in the env option should not start with $. I.e. you want to do env: {MY_ENV: "test"}, not env: {$MY_ENV: "test"}.

@ehmicky ehmicky closed this as completed May 24, 2024
@sahibjotsaggu
Copy link
Author

Okay, I see from https://github.com/sindresorhus/execa/blob/main/docs/bash.md#environment-variables that environment variables should get injected but I'm getting this type error I can't seem to resolve:

Screenshot 2024-05-24 at 12 23 27 PM
No overload matches this call.
  The last overload gave the following error.
    Object literal may only specify known properties, and 'env' does not exist in type 'URL'.ts(2769)
script.d.ts(22, 2): The last overload is declared here.

Any insight into this?

@ehmicky
Copy link
Collaborator

ehmicky commented May 24, 2024

Hi @sahibjotsaggu,

To help solving those issues, I would recommend:

  • Creating different issues since this is different from the initial problem
  • Pasting the code instead of a screenshot, so we can copy-paste it
  • For type-related problems, including a fully reproducing example with https://www.typescriptlang.org/play
  • Include environment information: Node.js version, TypeScript version, TypeScript config

I have created the following reproduction, and your example works fine for me.

Is there anything in the TypeScript documentation's troubleshooting section that's helping? In particular: the part about the minimum TypeScript version, and the part about ES modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants