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.

[Bug] bin scripts don't work for packages from the GitHub registry

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

Describe the bug

Packages installed from the github registry don’t get their bin scripts listed in yarn.lock. They are then not listed under yarn bin, and cannot be run directly using yarn run. The scripts are still present in node_modules/.bin if the node-modules linker is used.

It appears to be an issue with the GitHub package registry API that doesn’t include the bin field. However, it is quite unexpected that the bin scripts work with npm and yarn 1, but not yarn 2.

To Reproduce

Install this package: https://github.com/rkistner/yarn2-github-bin-script-issue/packages/321236. It is a public package, but you still need to authenticate with a github token.

  1. Configure the scope:
npmScopes:
  rkistner:
    npmRegistryServer: "https://npm.pkg.github.com/rkistner/"
    npmAuthToken: "your-token-here"
  1. Install the package: yarn add @rkistner/yarn2-github-bin-script-issue

  2. yarn bin -> not listed.

  3. Check yarn.lock -> no bin field under the @rkistner/yarn2-github-bin-script-issue package.

(Cannot reproduce with Sherlock, since an access token is required).

Environment if relevant (please complete the following information):

  • OS: Tested on Ubuntu
  • Node version: Tested on v12.6.0
  • Yarn version: Tested on 2.2.1

Additional context

Add any other context about the problem here.

Downloading the tgz file gives a package.json file like this, with the bin field as expected:

{
  "name": "@rkistner/yarn2-github-bin-script-issue",
  "repository": "https://github.com/rkistner/yarn2-github-bin-script-issue",
  "version": "1.0.3",
  "main": "index.js",
  "license": "MIT",
  "bin": "./bin.js",
  "publishConfig": {
    "registry": "https://npm.pkg.github.com"
  },
  "files": ["bin.js"]
}

However, via the GitHub registry API on https://npm.pkg.github.com/@rkistner/yarn2-github-bin-script-issue (need access token once again), we get back the response below. Note the lack of a bin field.

I haven’t been able to 100% confirm, but I think this is what is used to generate the info in yarn.lock, which is causing the issue here.

{
  "name": "@rkistner/yarn2-github-bin-script-issue",
  "description": "",
  "dist-tags": {
    "latest": "1.0.3"
  },
  "versions": {
    // (other versions here)
    "1.0.3": {
      "_from": "",
      "_id": "@rkistner/yarn2-github-bin-script-issue@1.0.3",
      "_nodeVersion": "12.6.0",
      "_npmUser": {},
      "_npmVersion": "6.14.2",
      "_shasum": "",
      "author": null,
      "bugs": {
        "url": "https://github.com/rkistner/yarn2-github-bin-script-issue/issues"
      },
      "dependencies": null,
      "description": "",
      "devDependencies": null,
      "dist": {
        "integrity": "sha512-t1+ihH6KSIJlI+glDV25dIABAuqnB7HBSrXiCrGGIhbSpMm6bbpF9djeAjCjcgelNgo2mMQ0f8FYpfSc5LRfkw==",
        "shasum": "c6d343b50cf757658c87663f38e5efd5fd4445e7",
        "tarball": "https://npm.pkg.github.com/download/@rkistner/yarn2-github-bin-script-issue/1.0.3/2616e60234d610b7aa9d44ab3442bcaae594a1eab916809a458200c8980812d7"
      },
      "gitHead": "28671a1c4eeb7a3aad7833e9d16ece684e6f3acb",
      "homepage": "https://github.com/rkistner/yarn2-github-bin-script-issue#readme",
      "license": "MIT",
      "main": "index.js",
      "name": "@rkistner/yarn2-github-bin-script-issue",
      "peerDependencies": null,
      "repository": {
        "type": "git",
        "url": "git+https://github.com/rkistner/yarn2-github-bin-script-issue.git"
      },
      "scripts": null,
      "version": "1.0.3"
    }
  },
  "time": {
    "1.0.0": "2020-07-20T14:53:55.000Z",
    "1.0.1": "2020-07-20T14:54:40.000Z",
    "1.0.2": "2020-07-20T14:54:56.000Z",
    "1.0.3": "2020-07-20T15:21:34.000Z"
  }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
brummeltecommented, Nov 2, 2020

They don’t work for private packages hosted on a GitLab registry either:

https://gitlab.com/gitlab-org/gitlab/-/issues/275992

2reactions
rkistnercommented, Jul 21, 2020

Thanks @arcanis, makes sense to architect it this way. One thing that may help on Yarn’s side is to detect mismatches like these and warn the user, since it’s quite hard to debug. Not sure whether it’s worth it though, especially if it gets fixed on GitHub’s side.

I’ve also contacted GitHub support, so they are aware of the issue. I’ll post here if there is any update from their side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug] Some bin scripts not working in CI environment ... - GitHub
The problem I'm having is that some of my existing scripts that execute packages from the bin directory do not work when they...
Read more >
Does not work with GitHub Packages registry as CLI option
Bug description When trying to install a package hosted on GitHub Packages it does not work with yarn but with npm.
Read more >
Unable to publish to GitHub Package Registry · Issue #53
I use the workflow you suggest, but the npm publish action on GitHub Package Registry doesn't work. On npmjs it works.
Read more >
[BUG] Regression: custom scripts not executed on ... - GitHub
Scripts from packages on a custom registry should be executed. This is working on npm 6, but not on npm 7 and npm...
Read more >
[BUG] npm does not setup child workspace's bin or use ...
These script work fine in the parent package.json, as the node_modules/.bin folder exists. However, it will crash in all child workspaces by ...
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