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] Can't publish using scoped private registry from parent directory #3993

Closed
1 task done
internalsystemerror opened this issue Nov 4, 2021 · 11 comments
Closed
1 task done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@internalsystemerror
Copy link

internalsystemerror commented Nov 4, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

After upgrading from Node v14 (and npm@6) to Node v16 (and npm@8), we're no longer able to use npm with a scoped private gitlab repository.

Note there are some issues which may be related to this, however the descriptions and error results differ enough that I felt it necessary to file this new issue.

Expected Behavior

Continue to function as before.

Steps To Reproduce

Build a package to dist/admin with the name containing a scope "@vendorname/packagename" and the "publishConfig" key containing a "@vendorname:registry" key. Set the appropriate npm config settings to allow publishing on node v14 and npm@6.

Update to node v16 and npm@8, this no longer works giving the following error:

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/dist/admin.git
npm ERR! ssh -oStrictHostKeyChecking=accept-new: line 1: ssh: not found
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-11-04T11_17_19_459Z-debug.log
node:child_process:903
    throw err;
    ^
Error: Command failed: npm publish --non-interactive dist/adminnpm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/dist/admin.git
npm ERR! ssh -oStrictHostKeyChecking=accept-new: line 1: ssh: not found
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-11-04T11_17_19_459Z-debug.log
node:child_process:903
    throw err;
    ^
Error: Command failed: npm publish --non-interactive dist/admin

As stated, the private registry is on gitlab so I'm not sure why it's trying to contact github. When running whoami, the following error occurs:

npm whoami --registry=https://gitlab.com/api/v4/packages/npm/
npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://registry.npmjs.org/-/whoami - Unauthorized

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ise/.npm/_logs/2021-11-04T13_22_08_098Z-debug.log

Environment

  • OS: Multiple (Ubuntu 20.04 + Alpine 3.14)
  • Node: 16.13.0
  • npm: 8.1.0
@internalsystemerror internalsystemerror added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Nov 4, 2021
@internalsystemerror
Copy link
Author

internalsystemerror commented Nov 8, 2021

Further to this, doing cd dist/admin && npm publish --non-interactive instead appears to at last find the package, but again when trying to publish tells me I'm unauthorised with npm's registry. This appears to be ignoring publishConfig for a scoped repository. npm@6 works fine.

EDIT: This was a local auth token issue (my local token didn't have write permissions). Changing to the package directory before running publish actually works. So the issue is specifically when trying to publish a subdirectory of the current working directory.

@internalsystemerror internalsystemerror changed the title [BUG] Can't publish using scoped private registry (or use npm whoami) [BUG] Can't publish using scoped private registry from parent directory Nov 9, 2021
@GasimGasimzada
Copy link

This happened to us as well and the following line got me curious git --no-replace-objects ls-remote ssh://git@github.com/dist/admin.git. Why dist/admin.git? From my understanding, there is a bug in npm8 where using slashes will result in the path being treated as a GIT repo. Doing cd dist/ && npm publish admin works as well

@GasimGasimzada
Copy link

GasimGasimzada commented Nov 16, 2021

I did a bit more digging and found the actual problem:

NPM CLI uses npm-package-arg to find out what the passed argument is. (Package: https://www.npmjs.com/package/npm-package-arg). So, I installed the package locally to do some tests and found the following results:

console.log(npa('dist'));

/*
Output: 

Result {
  type: 'tag',
  registry: true,
  where: undefined,
  raw: 'dist',
  name: 'dist',
  escapedName: 'dist',
  scope: undefined,
  rawSpec: '',
  saveSpec: null,
  fetchSpec: 'latest',
  gitRange: undefined,
  gitCommittish: undefined,
  hosted: undefined
}
*/

console.log(npa('dist/admin'));

/*
Output:
Result {
  type: 'git',
  registry: undefined,
  where: undefined,
  raw: 'dist/admin',
  name: undefined,
  escapedName: undefined,
  scope: undefined,
  rawSpec: 'dist/admin',
  saveSpec: 'github:dist/admin',
  fetchSpec: null,
  gitRange: undefined,
  gitCommittish: null,
  hosted: GitHost {
    sshtemplate: [Function: sshtemplate],
    sshurltemplate: [Function: sshurltemplate],
    browsetemplate: [Function: browsetemplate],
    browsefiletemplate: [Function: browsefiletemplate],
    docstemplate: [Function: docstemplate],
    httpstemplate: [Function: httpstemplate],
    filetemplate: [Function: filetemplate],
    shortcuttemplate: [Function: shortcuttemplate],
    pathtemplate: [Function: pathtemplate],
    bugstemplate: [Function: bugstemplate],
    hashformat: [Function: formatHashFragment],
    protocols: [ 'git:', 'http:', 'git+ssh:', 'git+https:', 'ssh:', 'https:' ],
    domain: 'github.com',
    treepath: 'tree',
    gittemplate: [Function: gittemplate],
    tarballtemplate: [Function: tarballtemplate],
    extract: [Function: extract],
    type: 'github',
    user: 'dist',
    auth: null,
    project: 'admin',
    committish: null,
    default: 'shortcut',
    opts: { noGitPlus: true, noCommittish: true }
  }
}
*/

As you can see, using npa returns returns GIT SSH result when subpaths are passed to it. If you add a trailing "/" at the end of your path, it should fix the issue:

console.log(npa('dist/admin/'));

/*
Result {
  type: 'directory',
  registry: undefined,
  where: '[PATH_TO_REPO]',
  raw: 'dist/admin/',
  name: undefined,
  escapedName: undefined,
  scope: undefined,
  rawSpec: 'dist/admin/',
  saveSpec: 'file:dist\\admin',
  fetchSpec: '[PATH_TO_REPO]\\dist\\admin',
  gitRange: undefined,
  gitCommittish: undefined,
  hosted: undefined
}
*/

@internalsystemerror
Copy link
Author

@GasimGasimzada Well found! Thanks. I'll see if we can test adding a trailing slash as an alternate workaround.

PowerKiKi added a commit to Ecodev/fab-speed-dial that referenced this issue Dec 7, 2021
PowerKiKi added a commit to Ecodev/natural that referenced this issue Dec 7, 2021
PowerKiKi added a commit to Ecodev/angular-natural-gallery that referenced this issue Dec 7, 2021
@PowerKiKi
Copy link

Adding a trailing "/" at the end of the path solved it for us, thank you !

@oliverlockwood
Copy link

In case it helps, I suspect this issue might be a combination of:

@hellwolf
Copy link

hellwolf commented Mar 1, 2022

... I mean, okay, but why... thanks anyways, a head scratching for a few hours

hellwolf added a commit to superfluid-finance/protocol-monorepo that referenced this issue Mar 1, 2022
@jpzwarte
Copy link

We ran into this as well; trailing slash fixed it.

@wraithgar
Copy link
Member

Yes, the shorthand of x/y translating to a git url is what's happening here. The trailing slash is required to let npm know it's a path, not the shorthand.

@boutell
Copy link

boutell commented Jun 7, 2022

My script is cd'ing into the appropriate folder and running npm publish the simple way, and I still get this error since upgrading to npm 8, even after a fresh npm login. It's a scoped private repo, as in these examples, but I've cd'd down into the actual directory. Not sure what I can do with that, but let me see what happens if I go out of my way not to cd into the folder... alas, no dice.

AhHa45 added a commit to alv-ch/angular-onscreen-material-keyboard that referenced this issue Jun 30, 2022
@zedfalco
Copy link

Thanks a lot @GasimGasimzada

Daniel-Lam added a commit to hmcts/ccd-case-ui-toolkit that referenced this issue Dec 9, 2023
Workaround for an apparent bug with npm and Node version >14 (see npm/cli#3993 for full details).
Daniel-Lam added a commit to hmcts/ccd-case-ui-toolkit that referenced this issue Dec 11, 2023
…Node 18 upgrade from master branch (#1639)

* EUI-6645 Restricted case acceess

* EUI-6645 Restricted case acceess

* EUI-6645 Restricted case access

* update version

* install

* Add translation package

* update version

* Update package

* yarn install

* Update package

* Merge from master

* Merge from master

* Merge from master

* Merge from master

* Merge from master

* EUI-8816 Restricted Case Access - Feature toggle for deployment to Production

* EUI-8816 Restricted Case Access - Feature toggle for deployment to Production

* EUI-8816 Restricted Case Access - Feature toggle for deployment to Production

* Update package version

* version update after merge from base branch

* EUI-8816 Restricted case access feature toggle functionality

* Upgrade to Node-18 and NG-15 (#1550)

* kick-off node 18 upgrade

* use pay component at local

* ng update @angular/core@12 @angular/cli@12 --force

* ng update @angular/material@12 --force

* ng update @angular/core@13 @angular/cli@13 --force

* ng update @angular/material@13 --force

* ng update @angular/core@14 @angular/cli@14 --force

* cdk 14

* ts version

* upgraes for fix

* upgrade rpx-xui-translation

* upgrade yargs-parser

* upgrade cli to 15

* fix damn ng breakdown

* ng update @angular/material@14 --force

* ng update @angular/core@15 @angular/cli@15 --force

* ng update @angular/material@15 --force

* correct compilation errors after upgrades

* ignore angular cache

* set new major version

* add yarn release file

* comment out broken lint task

* temporarily use ccpay-component from local

* fix tests

* fix tests

* upgrade to media viewer pre-release

* update version tag

* delete local ccpay dist folder

* use ccpay component prerelease

* skip the tasks (to be fixed later on)

* remove steps to unblock pre-release

* use node 14 for release

* Code tide

* package json update

* fix update package.json file and code tidy

* fix update package.json file

* fix update package.json file and code tidy

* package.json file update

* Using legacy angular material

* package.json version update

* fix: EXUI-787 - Fixed lint srcipt, lint issues, code issue. Code tidy

* updated codebase

* fix: EXUI-790	unit test now working; EXUI-996- Fixed dateTime Picker; Fix issue probate buttons - cancel and continue button

* package.json updated

* Update typography.scss

* Version update

* Update npmpublish.yml

* update polling service inline with sonarcloud - Security Hotspot

* code tidy

* added updated fork version of rx-polling library

* fix - EXUI-996 - fix issue with incorrect date formate

* App version updated and code tidy

* Update RELEASE-NOTES.md

* version update

* Update case-file-view-folder.component.ts

* Vesion update

* update test and karma config

* Update karma.conf.js

* Update case-file-view-folder-selector.component.spec.ts

* ccpay-web-component version updated

* version update

* fix broken functional test and update toolkit version

* version update

* rpx-xui-translation version update - 1.0.1

* @olusegz07 rpx-xui-translation version update - 1.0.2

---------

Co-authored-by: olusegun odunukan <olusegun.odunukan@hmcts.net>
Co-authored-by: Olu <142989683+olusegz07@users.noreply.github.com>

* fix yarn audit issue (#1634)

* fix yarn audit issue

* yarn audit fix

yarn audit fix

* Update RELEASE-NOTES.md

* Fix/ex UI 1151 yarn audit version (#1637)

* fix yarn audit issue

* yarn audit fix

yarn audit fix

* Update RELEASE-NOTES.md

* Version updated

* EUI-9048: Re-release of Case Flags v2.1 incorporating Angular 15 and Node 18 upgrade from master branch

Change to Node version 18 in GitHub npmpublish workflow, following upgrade of CCD Toolkit to Angular 15 and Node 18.

* Add trailing slash to build location

Workaround for an apparent bug with npm and Node version >14 (see npm/cli#3993 for full details).

---------

Co-authored-by: John Benjamin <john.benjamin@hmcts.net>
Co-authored-by: David Rajkumar Jayakumar <107850923+DavidJayakumar@users.noreply.github.com>
Co-authored-by: DavidJayakumar <David.Jayakumar@hmcts.net>
Co-authored-by: John Benjamin <90200268+johnbenjamin-hmcts@users.noreply.github.com>
Co-authored-by: codaimaster <55559010+codaimaster@users.noreply.github.com>
Co-authored-by: olusegun odunukan <olusegun.odunukan@hmcts.net>
Co-authored-by: Olu <142989683+olusegz07@users.noreply.github.com>
passiondev2024 added a commit to passiondev2024/natural that referenced this issue Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

9 participants