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

NPM install fails when a git+ssh project is linked #318

Closed
darcyclarke opened this issue Nov 8, 2019 · 8 comments
Closed

NPM install fails when a git+ssh project is linked #318

darcyclarke opened this issue Nov 8, 2019 · 8 comments
Labels
Bug thing that needs fixing

Comments

@darcyclarke
Copy link
Contributor

  Original bug ticket: [https://npm.community/t/9947](https://npm.community/t/9947)
  Originally filed: 2019-09-09T12:25:22.211Z
@darcyclarke darcyclarke added Bug Bug thing that needs fixing and removed Community labels Nov 8, 2019
@felix9
Copy link

felix9 commented Jan 28, 2020

I've run into this problem too. I have a repro here:

$ git clone git@github.com:felix9/npm-link-bug-1
$ git clone git@github.com:felix9/npm-link-bug-2
$ cd npm-link-bug-1
$ npm link
$ cd ../npm-link-bug-2
$ npm link npm-link-bug-1
$ npm install
npm ERR! Cannot read property '0' of undefined

This is where the error happens:

cli/lib/install/deps.js

Lines 60 to 61 in f533d61

if (requested.type === 'git' && requested.gitRange) {
const sameRepo = npa(child.package._from).fetchSpec === requested.fetchSpec

The parent package is requesting a git package with a gitRange.
The child package doesn't have a _from because linked packages don't have _from, so npm calls npa(undefined)

I'm unsure what the right fix is.

@truckingsim
Copy link

@felix9 I think the second clone is supposed to be npm-link-bug-2 you have -1 twice.

@felix9
Copy link

felix9 commented Jan 28, 2020

oops, yeah, fixed.

@isaacs
Copy link
Contributor

isaacs commented Jan 28, 2020

Ah, fantastic, it's been nagging at me that we don't have a repro case for that npa bug.

Thanks!

@darcyclarke darcyclarke modified the milestone: OSS - Sprint 17 Oct 5, 2020
@SeanDunford
Copy link

SeanDunford commented Dec 16, 2020

Does this mean that git hosted repos with gitRange should be avoided?

Just added one of these to my project and started noticing the error.

cat ~/.npm/_logs/2020-12-16T05_17_25_293Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'outdated' ]
2 info using npm@6.14.5
3 info using node@v14.15.0
4 verbose npm-session 695d8a0006d4fbbf
5 verbose stack TypeError: Cannot read property '0' of undefined
5 verbose stack     at npa (/usr/local/lib/node_modules/npm/node_modules/npm-package-arg/npa.js:34:25)
5 verbose stack     at doesChildVersionMatch (/usr/local/lib/node_modules/npm/lib/install/deps.js:61:22)
5 verbose stack     at versionMatch (/usr/local/lib/node_modules/npm/lib/install/deps.js:762:12)
5 verbose stack     at Array.filter (<anonymous>)
5 verbose stack     at exports.findRequirement (/usr/local/lib/node_modules/npm/lib/install/deps.js:772:23)
5 verbose stack     at findChild (/usr/local/lib/node_modules/npm/lib/install/deps.js:125:17)
5 verbose stack     at computeMetadata (/usr/local/lib/node_modules/npm/lib/install/deps.js:135:9)
5 verbose stack     at /usr/local/lib/node_modules/npm/lib/outdated.js:81:16
5 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-tree/rpt.js:162:20
6 verbose cwd ~/projects/pantheon/wellness
7 verbose Darwin 19.6.0
8 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "outdated"
9 verbose node v14.15.0
10 verbose npm  v6.14.5
11 error Cannot read property '0' of undefined
12 verbose exit [ 1, true ]

Is there a patch for const sameRepo = npa(child.package._from).fetchSpec === requested.fetchSpec that doesn't depend on the nonexistent child.packge._from value?

Edit: Duplicates #2262 #1542

@v1talii-dev
Copy link

I've run into this problem too. I have a repro here:

$ git clone git@github.com:felix9/npm-link-bug-1
$ git clone git@github.com:felix9/npm-link-bug-2
$ cd npm-link-bug-1
$ npm link
$ cd ../npm-link-bug-2
$ npm link npm-link-bug-1
$ npm install
npm ERR! Cannot read property '0' of undefined

This is where the error happens:

cli/lib/install/deps.js

Lines 60 to 61 in f533d61

if (requested.type === 'git' && requested.gitRange) {
const sameRepo = npa(child.package._from).fetchSpec === requested.fetchSpec

The parent package is requesting a git package with a gitRange.
The child package doesn't have a _from because linked packages don't have _from, so npm calls npa(undefined)
I'm unsure what the right fix is.

How did you fix this problem?

@felix9
Copy link

felix9 commented May 14, 2021

@VitaliyDemchuk I never found a fix or workaround, I just gave up on using npm link

@v1talii-dev
Copy link

@felix9 I used this hack, but it is a very bad solution and I would like to find a more acceptable option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing
6 participants