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.

[Feature] Add support for package.json script variables

See original GitHub issue
  • I’d be willing to implement a fix

Describe the bug

When using “yarn pack” in Yarn v1, package.json variables (such as npm_package_version) are honoured. This seems to not be th case in yarn v2.

To Reproduce

I have a package.json which defines a “pack” script like so:

  "scripts": {
    "pack": "yarn pack --filename my-file-v$npm_package_version.tar.gz",
  }

The error when I run “yarn run pack” is Internal Error: Unbound variable "npm_package_version"

The minimal information needed to reproduce your issue (ideally a package.json with a single dep). Note that bugs without minimal reproductions might be closed.

Environment if relevant (please complete the following information):

  • OS: Linux
  • Node version 10.22.0
  • Yarn version 2.1.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:31 (19 by maintainers)

github_iconTop GitHub Comments

11reactions
lucasfelicianocommented, Jan 6, 2021

Other use case is when it’s used on .env files for example:

PORT=7000
REACT_APP_VERSION=$npm_package_version

With yarn2 this is not possible and it is quite surprising that it doesn’t work by design

9reactions
Ayc0commented, Apr 15, 2021

👋 I’m a bit late to the party but I also needed the yarn classic var envs, so I created a plugin for that: https://github.com/Ayc0/yarn-plugin-envs

@jheaff1 it should fit your needs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Three Things You Didn't Know You Could Do with npm Scripts
npm scripts are a great way to automate common tasks during your Node.js development flow. In this blog post we'll cover the basics...
Read more >
scripts - npm Docs
The "scripts" property of your package.json file supports a number of built-in scripts and their preset life cycle events as well as arbitrary...
Read more >
How can I use variables in package.json? - Stack Overflow
Any property from package.json can be referenced from scripts, prefix it with $npm_package and adding an _<prop> (underscore + property) for ...
Read more >
Scripting inside package.json
Run npm run to see available scripts. Binaries of locally install packages are made available in the PATH , so you can run...
Read more >
Running cross-platform tasks via npm package scripts - 2ality
npm run Scripts available via `npm run-script`: help scripts-help -w 40 ... npm run temporarily adds entries to the shell PATH variable ......
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