Open KevinVR opened 7 years ago
+1
For me pkg.name is undefined, so I added additional check to Kevin fix and it works.
I think this is the same issue as #17858
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.
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
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.
Updating npm helped. In case one uses nvm here is how to do that.
I'm opening this issue because:
What's going wrong?
When installing packages:
How can the CLI team reproduce the problem?
supporting information:
npm -v
prints: 5.3.0node -v
prints: v6.10.2npm 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