Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Undefined pkg variable in node_modules\npm\lib\unbuild.js:62 #17865

Open
1 task done
KevinVR opened this issue Jul 20, 2017 · 6 comments
Open
1 task done

Undefined pkg variable in node_modules\npm\lib\unbuild.js:62 #17865

KevinVR opened this issue Jul 20, 2017 · 6 comments
Labels

Comments

@KevinVR
Copy link

KevinVR commented Jul 20, 2017

I'm opening this issue because:

  • npm is crashing

What's going wrong?

When installing packages:

npm ERR! Cannot read property '0' of undefined

How can the CLI team reproduce the problem?

1631 warn ionic-angular@3.5.3 requires a peer of @angular/common@4.1.3 but none was installed.
1632 warn ionic-angular@3.5.3 requires a peer of @angular/compiler@4.1.3 but none was installed.
1633 warn ionic-angular@3.5.3 requires a peer of @angular/compiler-cli@4.1.3 but none was installed.
1634 warn ionic-angular@3.5.3 requires a peer of @angular/core@4.1.3 but none was installed.
1635 warn ionic-angular@3.5.3 requires a peer of @angular/forms@4.1.3 but none was installed.
1636 warn ionic-angular@3.5.3 requires a peer of @angular/http@4.1.3 but none was installed.
1637 warn ionic-angular@3.5.3 requires a peer of @angular/platform-browser@4.1.3 but none was installed.
1638 warn ionic-angular@3.5.3 requires a peer of @angular/platform-browser-dynamic@4.1.3 but none was installed.
1639 warn ionic-angular@3.5.3 requires a peer of rxjs@5.4.0 but none was installed.
1640 warn ionic-angular@3.5.3 requires a peer of zone.js@0.8.12 but none was installed.
1641 warn visual-inventory@0.0.1 No repository field.
1642 warn visual-inventory@0.0.1 No license field.
1643 verbose stack TypeError: Cannot read property '0' of undefined
1643 verbose stack     at rmStuff (C:\Users\me\AppData\Roaming\npm\node_modules\npm\lib\unbuild.js:61:24)
1643 verbose stack     at tryCatcher (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
1643 verbose stack     at ret (eval at makeNodePromisifiedEval (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
1643 verbose stack     at lifecycle.then.then (C:\Users\me\AppData\Roaming\npm\node_modules\npm\lib\install\action\unbuild.js:12:12)
1643 verbose stack     at tryCatcher (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
1643 verbose stack     at Promise._settlePromiseFromHandler (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
1643 verbose stack     at Promise._settlePromise (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
1643 verbose stack     at Promise._settlePromise0 (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
1643 verbose stack     at Promise._settlePromises (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
1643 verbose stack     at Async._drainQueue (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
1643 verbose stack     at Async._drainQueues (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
1643 verbose stack     at Immediate.Async.drainQueues (C:\Users\me\AppData\Roaming\npm\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
1643 verbose stack     at runCallback (timers.js:666:20)
1643 verbose stack     at tryOnImmediate (timers.js:639:5)
1643 verbose stack     at processImmediate [as _immediateCallback] (timers.js:611:5)
1644 verbose cwd C:\Users\me\Documents\GitHub\hdui
1645 verbose Windows_NT 10.0.15063
1646 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\me\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "ionic-angular@latest" "--save" "--save-exact"
1647 verbose node v6.10.2
1648 verbose npm  v5.3.0
1649 error Cannot read property '0' of undefined
1650 verbose exit [ 1, true ]

supporting information:

  • npm -v prints: 5.3.0

  • node -v prints: v6.10.2

  • npm config get registry prints: https://registry.npmjs.org/

  • Windows, OS X/macOS, or Linux?: Windows

My temporary fix

Go to lib\unbuild.js:62

Find

parent = pkg.name[0] === '@' ? path.dirname(path.dirname(folder)) : path.dirname(folder)

Replace with

  var parent;
  if (typeof pkg !== 'undefined') {
      parent = pkg.name[0] === '@' ? path.dirname(path.dirname(folder)) : path.dirname(folder)
  }
  else {
      parent = path.dirname(folder)
  }
@PavelEmelyanov
Copy link

+1

For me pkg.name is undefined, so I added additional check to Kevin fix and it works.

@kenany kenany added the npm5 label Jul 20, 2017
@robinhouston
Copy link

I think this is the same issue as #17858

@atuttle
Copy link

atuttle commented Sep 15, 2017

I am not 100% sure but I think I started seeing this issue after using (a probably very outdated version of) N to install a recent version of node. I tried completely removing node and npm, reinstalling, and re-upgrading to the latest npm...

$ node -v && npm -v
v8.5.0
5.4.2

Even a simple npm install --save-dev jest was failing for me. Here are the relevant lines from one of the (many) debug logs npm created from my (many) different attempts to fix it.

...
18170 silly unbuild p-pipe@1.2.0
18171 info lifecycle p-pipe@1.2.0~preuninstall: p-pipe@1.2.0
18172 info lifecycle p-pipe@1.2.0~uninstall: p-pipe@1.2.0
18173 verbose unbuild rmStuff p-pipe@1.2.0 from /Users/atcodes/DEV/myapp/node_modules
18174 info lifecycle p-pipe@1.2.0~postuninstall: p-pipe@1.2.0
18175 silly unbuild os-tmpdir
18176 info lifecycle undefined~preuninstall: undefined
18177 info lifecycle undefined~uninstall: undefined
18178 silly unbuild os-locale
18179 info lifecycle undefined~preuninstall: undefined
18180 info lifecycle undefined~uninstall: undefined
18181 silly unbuild expand-tilde
18182 info lifecycle undefined~preuninstall: undefined
18183 info lifecycle undefined~uninstall: undefined
18184 silly unbuild os-homedir
18185 info lifecycle undefined~preuninstall: undefined
18186 info lifecycle undefined~uninstall: undefined
18187 silly unbuild optimist
18188 info lifecycle undefined~preuninstall: undefined
18189 info lifecycle undefined~uninstall: undefined
18190 silly unbuild wordwrap
18191 info lifecycle undefined~preuninstall: undefined
18192 info lifecycle undefined~uninstall: undefined
18193 silly unbuild onetime
18194 info lifecycle undefined~preuninstall: undefined
18195 info lifecycle undefined~uninstall: undefined
18196 silly unbuild object.omit
18197 info lifecycle undefined~preuninstall: undefined
18198 info lifecycle undefined~uninstall: undefined
18199 silly unbuild loader-utils
18200 info lifecycle undefined~preuninstall: undefined
18201 info lifecycle undefined~uninstall: undefined
18202 silly unbuild figures
18203 info lifecycle undefined~preuninstall: undefined
18204 info lifecycle undefined~uninstall: undefined
18205 silly unbuild escope
18206 info lifecycle undefined~preuninstall: undefined
18207 info lifecycle undefined~uninstall: undefined
18208 silly unbuild esrecurse
18209 info lifecycle undefined~preuninstall: undefined
18210 info lifecycle undefined~uninstall: undefined
18211 silly unbuild object-assign
18212 info lifecycle undefined~preuninstall: undefined
18213 info lifecycle undefined~uninstall: undefined
18214 silly unbuild is-fullwidth-code-point
18215 info lifecycle undefined~preuninstall: undefined
18216 info lifecycle undefined~uninstall: undefined
18217 silly unbuild is-finite
18218 info lifecycle undefined~preuninstall: undefined
18219 info lifecycle undefined~uninstall: undefined
18220 silly unbuild number-is-nan
18221 info lifecycle undefined~preuninstall: undefined
18222 info lifecycle undefined~uninstall: undefined
18223 silly unbuild normalize-path
18224 info lifecycle undefined~preuninstall: undefined
18225 info lifecycle undefined~uninstall: undefined
18226 silly unbuild natural-compare
18227 info lifecycle undefined~preuninstall: undefined
18228 info lifecycle undefined~uninstall: undefined
18229 silly unbuild mute-stream
18230 info lifecycle undefined~preuninstall: undefined
18231 info lifecycle undefined~uninstall: undefined
18232 silly unbuild debug
18233 info lifecycle undefined~preuninstall: undefined
18234 info lifecycle undefined~uninstall: undefined
18235 verbose unlock done using /Users/atcodes/.npm/_locks/staging-025b0ff04119ea5d.lock for /Users/atcodes/DEV/myapp/node_modules/.staging
18236 verbose stack TypeError: Cannot read property '0' of undefined
18236 verbose stack     at rmStuff (/Users/atcodes/.npm_globals/lib/node_modules/npm/lib/unbuild.js:66:24)
18236 verbose stack     at tryCatcher (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
18236 verbose stack     at ret (eval at makeNodePromisifiedEval (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
18236 verbose stack     at lifecycle.then.then (/Users/atcodes/.npm_globals/lib/node_modules/npm/lib/install/action/unbuild.js:12:12)
18236 verbose stack     at tryCatcher (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
18236 verbose stack     at Promise._settlePromiseFromHandler (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:512:31)
18236 verbose stack     at Promise._settlePromise (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:569:18)
18236 verbose stack     at Promise._settlePromise0 (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
18236 verbose stack     at Promise._settlePromises (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
18236 verbose stack     at Promise._fulfill (/Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:638:18)
18236 verbose stack     at /Users/atcodes/.npm_globals/lib/node_modules/npm/node_modules/bluebird/js/release/nodeback.js:42:21
18236 verbose stack     at <anonymous>
18237 verbose cwd /Users/atcodes/DEV/myapp
18238 verbose Darwin 16.5.0
18239 verbose argv "/usr/local/bin/node" "/Users/atcodes/.npm_globals/bin/npm" "install" "--save-dev" "jest"
18240 verbose node v8.5.0
18241 verbose npm  v5.4.2
18242 error Cannot read property '0' of undefined
18243 verbose exit [ 1, true ]

Based on the comments above, here's what ended up working for me:

  var parent;
  if (typeof pkg !== 'undefined' && typeof pkg.name !== 'undefined') {
      parent = pkg.name[0] === '@' ? path.dirname(path.dirname(folder)) : path.dirname(folder)
  } else {
      parent = path.dirname(folder)
  }

I don't know where the undefined package name is coming from. Would be happy to help debug if someone wants to get in touch sooner rather than later (before all of the context falls out of my brain)...

But for now I'm back on my feet.

@uglow
Copy link

uglow commented Sep 22, 2017

I'm seeing similar behaviour on Linux, but not on MacOS. Using Node 8.5.0 and NPM 5.3.0.

It has worked once on Linux, but seeing lots of this:

...
http fetch GET 200 https://registry.npmjs.org/mime/-/mime-1.4.0.tgz 29ms
http fetch GET 200 https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz 30ms
http fetch GET 200 https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz 20ms
http fetch GET 200 https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.30.tgz 927ms
25hnpm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
npm info lifecycle undefined~preuninstall: undefined
npm info lifecycle undefined~uninstall: undefined
...
npm ERR! opts.mkdirpAsync is not a function

@kosmjon
Copy link

kosmjon commented Feb 22, 2018

unbuild.js is still broken in 5.5.1 Is there a version that has a fix? For now I will patch source as shown above.

@germanz
Copy link

germanz commented Jun 14, 2018

Updating npm helped. In case one uses nvm here is how to do that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants