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] Cannot set properties of null (setting 'peer') #6622

Closed
2 tasks done
dderjoel opened this issue Jul 3, 2023 · 3 comments · Fixed by #7579
Closed
2 tasks done

[BUG] Cannot set properties of null (setting 'peer') #6622

dderjoel opened this issue Jul 3, 2023 · 3 comments · Fixed by #7579
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release

Comments

@dderjoel
Copy link

dderjoel commented Jul 3, 2023

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

I am getting the error:

46 verbose stack TypeError: Cannot set properties of null (setting 'peer')
46 verbose stack     at visit (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:101:54)
46 verbose stack     at visitNode (/usr/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:58:25)
46 verbose stack     at next (/usr/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:44:19)
46 verbose stack     at depth (/usr/lib/node_modules/npm/node_modules/treeverse/lib/depth-descent.js:83:10)
46 verbose stack     at depth (/usr/lib/node_modules/npm/node_modules/treeverse/lib/depth.js:27:12)
46 verbose stack     at unsetFlag (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:96:5)
46 verbose stack     at /usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:63:7
46 verbose stack     at Map.forEach (<anonymous>)
46 verbose stack     at calcDepFlagsStep (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:41:17)
46 verbose stack     at visit (/usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:12:20)

I've then checked /usr/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/calc-dep-flags.js:101:54) and added a console.error({node}); to line 101, to get more insight. It seems like target is null, I've put the last three nodes below.

I've created a mwe here. To reproduce, execute npm i and then try to install npm i measuresuite@latest again. It works well for the first install and any subsequent install, iff node_modules are deleted beforehand.
I am the maintainer of measuresuite, which is a C-library with a gyp file. The native code it build into ./build/Release/measuresuite which I am trying to reference from measuresuite-native-module. c.f. package.json:47

Possibly it is not an issue with npmcli (although it seems related like here), but with how I am packaging measuresuite, but I could not find any better documentation of how to package a native module. (and it used to work fine just like that).
I'm more than happy to provide more information or data if needed, but I am lost and don't know where to debug / which data is needed.

Last three nodes:

{
  node: ArboristLink {
    name: 'measuresuite-native-module',
    location: 'node_modules/measuresuite-native-module',
    path: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite-native-module',
    realpath: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite/build/Release/measuresuite.node',
    resolved: 'file:measuresuite/build/Release/measuresuite.node',
    optional: true,
    errors: [ [Object] ],
    edgesIn: Set(1) {
      { node_modules/measuresuite prod measuresuite-native-module@file:./build/Release/measuresuite.node }
    },
    target: ArboristNode {
      name: 'measuresuite.node',
      location: 'node_modules/measuresuite/build/Release/measuresuite.node',
      path: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite/build/Release/measuresuite.node',
      dev: true,
      optional: true,
      errors: [Array]
    }
  }
}
{
  node: ArboristLink {
    name: 'measuresuite-native-module',
    location: 'node_modules/measuresuite-native-module',
    path: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite-native-module',
    realpath: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite/build/Release/measuresuite.node',
    resolved: 'file:measuresuite/build/Release/measuresuite.node',
    errors: [ [Object] ],
    edgesIn: Set(1) {
      { node_modules/measuresuite prod measuresuite-native-module@file:./build/Release/measuresuite.node }
    },
    target: ArboristNode {
      name: 'measuresuite.node',
      location: 'node_modules/measuresuite/build/Release/measuresuite.node',
      path: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite/build/Release/measuresuite.node',
      optional: true,
      errors: [Array]
    }
  }
}
{⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂)  idealTree: timing arborist:ctor Completed in 1ms
  node: ArboristLink {
    name: 'measuresuite-native-module',
    packageName: 'measuresuite.node',
    location: 'node_modules/measuresuite-native-module',
    path: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite-native-module',
    realpath: '/home/joel/dev/6mwe/mwe-measuresuite/node_modules/measuresuite/build/Release/measuresuite.node',
    resolved: 'file:measuresuite/build/Release/measuresuite.node',
    dev: true,
    optional: true,
    edgesIn: Set(1) {
      { node_modules/measuresuite prod measuresuite-native-module@file:./build/Release/measuresuite.node }
    },
    target: null
  }
}

Expected Behavior

That npm i measuresuite@latest does not fail.

Steps To Reproduce

git clone https://github.com/dderjoel/mwe-measuresuite.git
cd mwe-measuresuite
npm i
npm i measuresuite@latest

Environment

  • npm: 9.8.0
  • Node.js: v20.3.1
  • OS Name: ArchLinux: (uname -a: Linux arch4 6.3.9-arch1-1 archive: committable offline dependency archive #1 SMP PREEMPT_DYNAMIC Wed, 21 Jun 2023 20:46:20 +0000 x86_64 GNU/Linux)
  • System Model Name: Lenovo T490
  • npm config: npm config ls:
; "user" config from /home/joel/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /usr/bin/node
; node version = v20.3.1
; npm local prefix = /home/joel/dev/6mwe/mwe-measuresuite
; npm version = 9.7.2
; cwd = /home/joel/dev/6mwe/mwe-measuresuite
; HOME = /home/joel

npm config ls -l:

; "default" config from default values

_auth = (protected) 
access = null 
all = false 
allow-same-version = false 
also = null 
audit = true 
audit-level = null 
auth-type = "web" 
before = null 
bin-links = true 
browser = null 
ca = null 
cache = "/home/joel/.npm" 
cache-max = null 
cache-min = 0 
cafile = null 
call = "" 
cert = null 
ci-name = null 
cidr = null 
color = true 
commit-hooks = true 
depth = null 
description = true 
dev = false 
diff = [] 
diff-dst-prefix = "b/" 
diff-ignore-all-space = false 
diff-name-only = false 
diff-no-prefix = false 
diff-src-prefix = "a/" 
diff-text = false 
diff-unified = 3 
dry-run = false 
editor = "nvim" 
engine-strict = false 
fetch-retries = 2 
fetch-retry-factor = 10 
fetch-retry-maxtimeout = 60000 
fetch-retry-mintimeout = 10000 
fetch-timeout = 300000 
force = false 
foreground-scripts = false 
format-package-lock = true 
fund = true 
git = "git" 
git-tag-version = true 
global = false 
global-style = false 
globalconfig = "/usr/etc/npmrc" 
heading = "npm" 
https-proxy = null 
if-present = false 
ignore-scripts = false 
include = [] 
include-staged = false 
include-workspace-root = false 
init-author-email = "" 
init-author-name = "" 
init-author-url = "" 
init-license = "ISC" 
init-module = "/home/joel/.npm-init.js" 
init-version = "1.0.0" 
init.author.email = "" 
init.author.name = "" 
init.author.url = "" 
init.license = "ISC" 
init.module = "/home/joel/.npm-init.js" 
init.version = "1.0.0" 
install-links = false 
install-strategy = "hoisted" 
json = false 
key = null 
legacy-bundling = false 
legacy-peer-deps = false 
link = false 
local-address = null 
location = "user" 
lockfile-version = null 
loglevel = "notice" 
logs-dir = null 
logs-max = 10 
; long = false ; overridden by cli
maxsockets = 15 
message = "%s" 
metrics-registry = "https://registry.npmjs.org/" 
node-options = null 
noproxy = [""] 
npm-version = "9.7.2" 
offline = false 
omit = [] 
omit-lockfile-registry-resolved = false 
only = null 
optional = null 
otp = null 
pack-destination = "." 
package = [] 
package-lock = true 
package-lock-only = false 
parseable = false 
prefer-dedupe = false 
prefer-offline = false 
prefer-online = false 
prefix = "/usr" 
preid = "" 
production = null 
progress = true 
provenance = false 
provenance-file = null 
proxy = null 
read-only = false 
rebuild-bundle = true 
registry = "https://registry.npmjs.org/" 
replace-registry-host = "npmjs" 
save = true 
save-bundle = false 
save-dev = false 
save-exact = false 
save-optional = false 
save-peer = false 
save-prefix = "^" 
save-prod = false 
scope = "" 
script-shell = null 
searchexclude = "" 
searchlimit = 20 
searchopts = "" 
searchstaleness = 900 
shell = "/bin/zsh" 
shrinkwrap = true 
sign-git-commit = false 
sign-git-tag = false 
strict-peer-deps = false 
strict-ssl = true 
tag = "latest" 
tag-version-prefix = "v" 
timing = false 
tmp = "/tmp" 
umask = 0 
unicode = true 
update-notifier = true 
usage = false 
user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}" 
userconfig = "/home/joel/.npmrc" 
version = false 
versions = false 
viewer = "man" 
which = null 
workspace = [] 
workspaces = null 
workspaces-update = true 
yes = null 

; "user" config from /home/joel/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; "cli" config from command line options

long = true

@dderjoel dderjoel added Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release labels Jul 3, 2023
@dderjoel dderjoel changed the title [BUG] Cannot set properties of null (settting 'peer') [BUG] Cannot set properties of null (setting 'peer') Jul 7, 2023
@hschulz
Copy link

hschulz commented Mar 29, 2024

I just encountered this problem and would like to add some information for my personal workaround.

My project has some private scoped packages as dependencies that I have published on GitHub.
When I now use either npm link or local paths in the package.json and I do an npm update and/or npm install I encounter the npm ERR! Cannot set properties of null (setting 'peer') error.

After some time I discovered that I can prevent the error when I remove the .npmrc config for the org scope which was part of the recommended configuration from the GitHub documentation on private packages.

@<myorg>:registry=https://npm.pkg.github.com/

When I remove that line I can use npm link or file paths fine; although I had to link all scoped dependencies at the same time.

@cascornelissen
Copy link

That's an interesting detail @hschulz, our situation is exactly the same with a scope for our company-specific packages defined in .npmrc to ensure these are fetched from an internal Artifactory registry.

Great find! I hope it helps whoever will debug this 😅

@douglasg14b
Copy link

One would think there should be an assertion here that prints a more helpful error message :/

Been struggling with this for a while.

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

Successfully merging a pull request may close this issue.

4 participants