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] npm ERR! Cannot destructure property 'name' of 'node' as it is null. #2548

Closed
dmnsgn opened this issue Jan 26, 2021 · 8 comments
Closed
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@dmnsgn
Copy link

dmnsgn commented Jan 26, 2021

Opening a new issue as requested by @isaacs #1832 (comment)

Current Behavior:

Installing a dependency from a GitHub URL fails.

Expected Behavior:

Dependency is installed without error.

Steps To Reproduce:

npm init -y
npm i -D git://github.com/GoogleChromeLabs/critters.git

Yields:

npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js install --cache=/Users/my-name/.npm/_cacache --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit
npm ERR! npm ERR! code ERESOLVE
npm ERR! npm ERR! Cannot destructure property 'name' of 'node' as it is null.

Environment:

  • OS: MacOS 10.15.6
  • Node: v15.5.1
  • npm: 7.4.0
@dmnsgn dmnsgn added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Jan 26, 2021
isaacs added a commit to npm/pacote that referenced this issue Jan 29, 2021
If a git dependency has conflicting peerDependencies, dependencies with
engines fields that don't match the current environment, and so on, it
isn't much help to crash the installation for these issues.  The user
installing the git dependency is likely not in a position to fix them,
but from npm and Arborist's points of view, it is the 'main' project
that has a problem (since the install is being run as a separate
process).

This commit passes '--force' to the npm child process that installs
dependencies for git packages before running their 'prepare' script, to
ignore all such issues (or reduce them to warnings).

Related to: npm/cli#2548
isaacs added a commit to npm/arborist that referenced this issue Jan 29, 2021
If the virtualRoot node has a sourceReference, and that sourceReference
node would get its devDep edges loaded, then the virtualRoot node should
as well.

This caused a very useless ERESOLVE error, which could not be properly
forced away, when installing in a project that had conflicting peer deps
in its dev tree.

Related to: npm/cli#2548
isaacs added a commit to npm/arborist that referenced this issue Jan 29, 2021
If the virtualRoot node has a sourceReference, and that sourceReference
node would get its devDep edges loaded, then the virtualRoot node should
as well.

This caused a very useless ERESOLVE error, which could not be properly
forced away, when installing in a project that had conflicting peer deps
in its dev tree.

Related to: npm/cli#2548
@isaacs
Copy link
Contributor

isaacs commented Jan 29, 2021

There are two issues here.

As it happens, critters has a legit peer dependency issue that we can't unravel (or rather, won't, as it would require explosively expensive traversals, in the general case -- there is a solution, but finding it is too hard).

The general situation is like this:
a@1 -> b@>=1
a@2 -> b@>=2
a@3 -> b@>=3
b@1 -> c@>=1
b@2 -> c@>=2
c@1 -> d@>=1
c@2 -> d@>=2
c@3 -> d@>=3

Then the package depends on {a: "1.x", d: "2.x"}.
npm resolves [email protected] to [email protected], and looks for b@>=1.
This resolves to [email protected], and now it looks for c@>=3
This resolves to [email protected], and now it looks for d@>=3, and whoops there's no version available that meets the d@>=3 requirement without conflicting with the root's dependency on [email protected]!

To solve this, we'd have to unwind the stack all the way back. So, we can't get [email protected], is there any other c@>=3 that doesn't have the same problem? No, so we can't use [email protected], is there any other b@>=1 that doesn't depend on a known-bad version of c? Yes, let's try [email protected], then [email protected], then [email protected], and we have our answer.

However...

There may be 10 different packages in the stack, across 10 different majors, each with 100 different patch versions to check, and this becomes O(n!) in many cases, for a very large n. Even pubgrub gives up eventually.

The solution, of course, is to just specify that you want b@2 and c@2 in your package.json, problem solved.

It would be easy enough for a human brain familiar with the code to see what deps need to be specified to give npm enough to go on. However, how would you know what's happening with such a useless ERESOLVE error?

First issue is that it wasn't tracking the dev dependencies properly when creating the tentative/virtual tree to resolve against. That's fixed by npm/arborist#214, so we get a proper ERESOLVE with a "current" value.

Second issue, this is happening in a project that isn't even critters! What are you supposed to do about it? Probably better to just ignore ERESOLVE errors that happen among transitive devDependencies at git preparation time, so that's fixed in npm/pacote#63

When those two land, this should work as expected.

isaacs added a commit to npm/arborist that referenced this issue Jan 29, 2021
If the virtualRoot node has a sourceReference, and that sourceReference
node would get its devDep edges loaded, then the virtualRoot node should
as well.

This caused a very useless ERESOLVE error, which could not be properly
forced away, when installing in a project that had conflicting peer deps
in its dev tree.

Related to: npm/cli#2548
isaacs added a commit to npm/arborist that referenced this issue Jan 29, 2021
If the virtualRoot node has a sourceReference, and that sourceReference
node would get its devDep edges loaded, then the virtualRoot node should
as well.

This caused a very useless ERESOLVE error, which could not be properly
forced away, when installing in a project that had conflicting peer deps
in its dev tree.

Related to: npm/cli#2548
isaacs added a commit to npm/arborist that referenced this issue Feb 1, 2021
If the virtualRoot node has a sourceReference, and that sourceReference
node would get its devDep edges loaded, then the virtualRoot node should
as well.

This caused a very useless ERESOLVE error, which could not be properly
forced away, when installing in a project that had conflicting peer deps
in its dev tree.

Related to: npm/cli#2548

PR-URL: #214
Credit: @isaacs
Close: #214
Reviewed-by: @nlf
isaacs added a commit to npm/pacote that referenced this issue Feb 1, 2021
If a git dependency has conflicting peerDependencies, dependencies with
engines fields that don't match the current environment, and so on, it
isn't much help to crash the installation for these issues.  The user
installing the git dependency is likely not in a position to fix them,
but from npm and Arborist's points of view, it is the 'main' project
that has a problem (since the install is being run as a separate
process).

This commit passes '--force' to the npm child process that installs
dependencies for git packages before running their 'prepare' script, to
ignore all such issues (or reduce them to warnings).

Related to: npm/cli#2548

PR-URL: #63
Credit: @isaacs
Close: #63
Reviewed-by: @nlf
@darcyclarke
Copy link
Contributor

@dmnsgn Closing: As I just tried this out & it seems to be working as of npm v7.5.1 - you can grab the latest via npm i -g npm@7.

@darcyclarke darcyclarke removed the Needs Triage needs review for next steps label Feb 2, 2021
@dmnsgn
Copy link
Author

dmnsgn commented Feb 2, 2021

I can confirm, error above doesn't show up anymore in 7.5.1 👍

@jcuna
Copy link

jcuna commented Feb 2, 2021

Seeing this pop up for me on [email protected].

[Container] 2021/02/02 21:17:08 Running command npm install
--
91 | TypeError: Cannot destructure property `stat` of 'undefined' or 'null'.
92 | at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/node-gyp/lib/index.js:2:29)
93 | at Module._compile (module.js:652:30)
94 | at Object.Module._extensions..js (module.js:663:10)
95 | at Module.load (module.js:565:32)
96 | at tryModuleLoad (module.js:505:12)
97 | at Function.Module._load (module.js:497:3)
98 | at Module.require (module.js:596:17)
99 | at require (internal/module.js:11:18)
100 | at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:4:55)
101 | at Module._compile (module.js:652:30)
102 | /usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:163
103 | throw new Error('call config.load() before reading values')

@jcuna
Copy link

jcuna commented Feb 2, 2021

Downgrading to 7.5.1 and still getting this error.


[Container] 2021/02/02 21:37:41 Running command npm install
--
91 | TypeError: Cannot destructure property `stat` of 'undefined' or 'null'.
92 | at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/node-gyp/lib/index.js:2:29)
93 | at Module._compile (module.js:652:30)
94 | at Object.Module._extensions..js (module.js:663:10)
95 | at Module.load (module.js:565:32)
96 | at tryModuleLoad (module.js:505:12)
97 | at Function.Module._load (module.js:497:3)
98 | at Module.require (module.js:596:17)
99 | at require (internal/module.js:11:18)
100 | at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/run-script-pkg.js:4:55)
101 | at Module._compile (module.js:652:30)
102 | /usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:163
103 | throw new Error('call config.load() before reading values')
104 | ^
105 |  
106 | Error: call config.load() before reading values
107 | at Config.get (/usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:163:13)
108 | at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:171:32)
109 | at emitOne (events.js:116:13)
110 | at process.emit (events.js:211:7)
111 | at process._fatalException (bootstrap_node.js:375:26)


@jcuna
Copy link

jcuna commented Feb 2, 2021

I'll open a new issue. Thanks

@simoncpu
Copy link

I am experiencing this on npm v7.6.1 as well: I ran npm update on AWS-CDK.

133 verbose stack TypeError: Cannot destructure property 'name' of 'node' as it is null.
133 verbose stack     at printNode (/Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/utils/explain-dep.js:29:5)
133 verbose stack     at explainNode (/Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/utils/explain-dep.js:13:3)
133 verbose stack     at explainEresolve (/Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/utils/explain-eresolve.js:24:24)
133 verbose stack     at report (/Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/utils/explain-eresolve.js:50:3)
133 verbose stack     at module.exports (/Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/utils/error-message.js:22:24)
133 verbose stack     at errorHandler (/Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/utils/error-handler.js:175:15)
133 verbose stack     at /Users/simoncpu/.npm-packages/lib/node_modules/npm/lib/npm.js:114:9
134 verbose cwd /my/directory/something/something
135 verbose Darwin 20.3.0
136 verbose argv "/Users/simoncpu/.n/bin/node" "/Users/simoncpu/.npm-packages/bin/npm" "update"
137 verbose node v14.16.0
138 verbose npm  v7.6.1
139 error Cannot destructure property 'name' of 'node' as it is null.
140 verbose exit 1

@gnapse
Copy link

gnapse commented Feb 23, 2022

I still experience this in npm 7.21.0

image

Here's the log file
0 verbose cli [
0 verbose cli   '/Users/ernesto/.fnm/node-versions/v16.8.0/installation/bin/node',
0 verbose cli   '/var/folders/tm/svfmwn415yx10pvtrg0c577w0000gp/T/fnm_multishell_48251_1645640939564/bin/npm',
0 verbose cli   'install'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 1ms
5 timing config:load:file:/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/Users/ernesto/code/doist/reactist/.npmrc Completed in 1ms
10 timing config:load:project Completed in 2ms
11 timing config:load:file:/Users/ernesto/.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:/Users/ernesto/.fnm/node-versions/v16.8.0/installation/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 8ms
19 timing npm:load:configload Completed in 8ms
20 timing npm:load:setTitle Completed in 13ms
21 timing npm:load:setupLog Completed in 0ms
22 timing config:load:flatten Completed in 2ms
23 timing npm:load:cleanupLog Completed in 2ms
24 timing npm:load:configScope Completed in 0ms
25 timing npm:load:projectScope Completed in 0ms
26 timing npm:load Completed in 26ms
27 timing arborist:ctor Completed in 1ms
28 timing idealTree:init Completed in 989ms
29 timing idealTree:userRequests Completed in 0ms
30 silly idealTree buildDeps
31 silly fetch manifest @doist/eslint-config@^7.1.0
32 timing arborist:ctor Completed in 0ms
33 http fetch GET 200 https://registry.npmjs.org/@doist%2feslint-config 886ms (cache hit)
34 silly fetch manifest @typescript-eslint/eslint-plugin@^4.33.0
35 http fetch GET 200 https://registry.npmjs.org/@typescript-eslint%2feslint-plugin 9ms (cache hit)
36 silly fetch manifest @typescript-eslint/parser@^4.33.0
37 http fetch GET 200 https://registry.npmjs.org/@typescript-eslint%2fparser 10ms (cache hit)
38 silly fetch manifest eslint@^7.32.0
39 http fetch GET 200 https://registry.npmjs.org/eslint 8ms (cache hit)
40 silly fetch manifest eslint-plugin-import@^2.25.3
41 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-import 3ms (cache hit)
42 silly fetch manifest eslint-plugin-prettier@^3.1.4
43 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-prettier 2ms (cache hit)
44 silly fetch manifest [email protected]
45 http fetch GET 200 https://registry.npmjs.org/prettier 1ms (cache hit)
46 silly fetch manifest eslint-plugin-react@^7.23.2
47 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-react 2ms (cache hit)
48 silly fetch manifest eslint-plugin-react-hooks@^4.3.0
49 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-react-hooks 4ms (cache hit)
50 silly fetch manifest eslint-plugin-simple-import-sort@^7.0.0
51 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-simple-import-sort 4ms (cache hit)
52 silly placeDep ROOT @doist/[email protected] REPLACE for: @doist/[email protected] want: ^7.1.0
53 silly placeDep ROOT @typescript-eslint/[email protected] OK for: @doist/[email protected] want: ^4.33.0
54 silly placeDep ROOT @typescript-eslint/[email protected] OK for: @typescript-eslint/[email protected] want: ^4.0.0
55 timing idealTree Completed in 2073ms
56 timing command:install Completed in 2091ms
57 verbose stack Error: could not resolve
57 verbose stack     at PlaceDep.failPeerConflict (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:470:25)
57 verbose stack     at PlaceDep.place (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:187:21)
57 verbose stack     at new PlaceDep (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:68:10)
57 verbose stack     at PlaceDep.placeInTree (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:342:26)
57 verbose stack     at PlaceDep.place (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:203:10)
57 verbose stack     at new PlaceDep (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:68:10)
57 verbose stack     at /Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:890:31
57 verbose stack     at Array.map (<anonymous>)
57 verbose stack     at Arborist.[buildDepStep] (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:890:8)
57 verbose stack     at async Arborist.buildIdealTree (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:206:7)
58 verbose cwd /Users/ernesto/code/doist/reactist
59 verbose Darwin 21.3.0
60 verbose argv "/Users/ernesto/.fnm/node-versions/v16.8.0/installation/bin/node" "/var/folders/tm/svfmwn415yx10pvtrg0c577w0000gp/T/fnm_multishell_48251_1645640939564/bin/npm" "install"
61 verbose node v16.8.0
62 verbose npm  v7.21.0
63 error code ERESOLVE
64 verbose stack TypeError: Cannot destructure property 'name' of 'node' as it is undefined.
64 verbose stack     at printNode (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/utils/explain-dep.js:34:5)
64 verbose stack     at explainNode (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/utils/explain-dep.js:16:3)
64 verbose stack     at explain (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/utils/explain-eresolve.js:38:16)
64 verbose stack     at report (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/utils/explain-eresolve.js:56:3)
64 verbose stack     at module.exports (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/utils/error-message.js:21:24)
64 verbose stack     at exitHandler (/Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/utils/exit-handler.js:152:19)
64 verbose stack     at /Users/ernesto/.fnm/node-versions/v16.8.0/installation/lib/node_modules/npm/lib/npm.js:156:9
65 verbose cwd /Users/ernesto/code/doist/reactist
66 verbose Darwin 21.3.0
67 verbose argv "/Users/ernesto/.fnm/node-versions/v16.8.0/installation/bin/node" "/var/folders/tm/svfmwn415yx10pvtrg0c577w0000gp/T/fnm_multishell_48251_1645640939564/bin/npm" "install"
68 verbose node v16.8.0
69 verbose npm  v7.21.0
70 error Cannot destructure property 'name' of 'node' as it is undefined.
71 verbose exit 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

6 participants