Code Monkey home page Code Monkey logo

Comments (8)

felix9 avatar felix9 commented on May 17, 2024 1

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

$ git clone [email protected]:felix9/npm-link-bug-1
$ git clone [email protected]: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.

from cli.

truckingsim avatar truckingsim commented on May 17, 2024

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

from cli.

felix9 avatar felix9 commented on May 17, 2024

oops, yeah, fixed.

from cli.

isaacs avatar isaacs commented on May 17, 2024

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

Thanks!

from cli.

SeanDunford avatar SeanDunford commented on May 17, 2024

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 [email protected]
3 info using [email protected]
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

from cli.

v1talii-dev avatar v1talii-dev commented on May 17, 2024

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

$ git clone [email protected]:felix9/npm-link-bug-1
$ git clone [email protected]: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?

from cli.

felix9 avatar felix9 commented on May 17, 2024

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

from cli.

v1talii-dev avatar v1talii-dev commented on May 17, 2024

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

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.