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

[Bug?]: Env variable substitution syntax causes an Internal Error when used within injectEnvironmentFiles option #6679

Open
1 task
SimpleCreations opened this issue Feb 6, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@SimpleCreations
Copy link

Self-service

  • I'd be willing to implement a fix

Describe the bug

As per docs:

Environment variables can be accessed from setting definitions by using the ${NAME} syntax when defining the values. By default Yarn will require the variables to be present, but this can be turned off by using either ${NAME-fallback} (which will return fallback if NAME isn't set) or ${NAME:-fallback} (which will return fallback if NAME isn't set, or is an empty string).

This syntax works in many fields in .yarnrc.yml, but not in injectEnvironmentFiles, in which Yarn throws an exception:

Internal Error: Invalid configuration key "enableColors"
    at t.get (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:148:24085)
    at Gs (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:140:58823)
    at Object.pretty (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:140:64888)
    at Ut (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:140:59309)
    at t.useWithSource (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:148:22779)
    at t.find (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:148:17411)
    at async Rve (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:744:6254)
    at async HDt (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:744:7600)
    at async Lk (/Users/USER/.cache/node/corepack/v1/yarn/4.6.0/yarn.js:745:142)

To reproduce

  1. Create a package.json file:
    {
      "name": "yarn-injectenvironmentfiles-bug-repro",
      "packageManager": "[email protected]",
      "private": true
    }
  2. Create a .yarnrc.yml file:
    injectEnvironmentFiles:
      - ".env.${APPLICATION_ENV}"
  3. Create an empty .env.production file
  4. Run
    corepack enable
    export APPLICATION_ENV=production
    yarn
  5. Observe an internal error thrown by Yarn

Expected behavior

No exception is thrown, yarn.lock is created, and future scripts are run with env variables defined in .env.production.

Actual behavior

An internal error is thrown.

Environment

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 22.13.1 - /private/var/folders/48/krhvg1rs02x0vdk6fkj994440000gp/T/xfs-ed5488c4/node
    Yarn: 4.6.0 - /private/var/folders/48/krhvg1rs02x0vdk6fkj994440000gp/T/xfs-ed5488c4/yarn
    npm: 10.9.2 - /opt/homebrew/bin/npm

Additional context

No response

@SimpleCreations SimpleCreations added the bug Something isn't working label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant