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 read properties of null (reading 'package') #4787

Open
2 tasks done
arimus opened this issue Apr 21, 2022 · 38 comments · May be fixed by #6604
Open
2 tasks done

[BUG] npm ERR! Cannot read properties of null (reading 'package') #4787

arimus opened this issue Apr 21, 2022 · 38 comments · May be fixed by #6604
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release Release 9.x work is associated with a specific npm 9 release Release 10.x

Comments

@arimus
Copy link

arimus commented Apr 21, 2022

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 do an initial npm install, which works fine. Subsequent runs result in the error:

...
111 timing command:i Completed in 1071ms
112 verbose stack TypeError: Cannot read properties of null (reading 'package')
112 verbose stack     at Link.set root [as root] (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:718:35)
112 verbose stack     at Link.replace (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:1155:17)
112 verbose stack     at PlaceDep.replaceOldDep (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:426:17)
112 verbose stack     at PlaceDep.placeInTree (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:304:12)
112 verbose stack     at PlaceDep.place (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:214:10)
112 verbose stack     at new PlaceDep (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:71:10)
112 verbose stack     at /Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:984:31
112 verbose stack     at Array.map (<anonymous>)
112 verbose stack     at Arborist.[buildDepStep] (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:984:8)
112 verbose stack     at async Arborist.buildIdealTree (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:216:7)
113 verbose cwd /Users/arimus/workspace/appbuilder-backend

Expected Behavior

npm install not failing with the above error.

Steps To Reproduce

Environment
Starting with NPM v8.6.0 (8.5.5 does not have this issue)

Config
A package.json with a tgz file dependency. Example:

{
  "name": "project",
  "version": "1.0.0",
  "description": "",
  "license": "",
  "repository": {
    "url": "http://github.com:arimus/test.git"
  },
  "author": "arimus",
  "scripts": {
    "tsc": "tsc --project tsconfig.json",
    "start": "node ./dist/index.js",
  },
  "dependencies": {
    "apollo-server-hapi": "./apollo-server-hapi-3.5.1.tgz"
  }
}

Run

npm i

Error

...
111 timing command:i Completed in 1071ms
112 verbose stack TypeError: Cannot read properties of null (reading 'package')
112 verbose stack     at Link.set root [as root] (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:718:35)
112 verbose stack     at Link.replace (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:1155:17)
112 verbose stack     at PlaceDep.replaceOldDep (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:426:17)
112 verbose stack     at PlaceDep.placeInTree (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:304:12)
112 verbose stack     at PlaceDep.place (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:214:10)
112 verbose stack     at new PlaceDep (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:71:10)
112 verbose stack     at /Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:984:31
112 verbose stack     at Array.map (<anonymous>)
112 verbose stack     at Arborist.[buildDepStep] (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:984:8)
112 verbose stack     at async Arborist.buildIdealTree (/Users/arimus/.nvm/versions/node/v16.13.1/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:216:7)
113 verbose cwd /Users/arimus/workspace/appbuilder-backend

Environment

  • npm: 8.6.0+
  • Node.js: v16.13.1
  • OS Name: OSX
  • npm config:
; node bin location = /Users/arimus/.nvm/versions/node/v16.13.1/bin/node
; cwd = /Users/arimus/workspace/appbuilder-backend
; HOME = /Users/arimus
; Run `npm config ls -l` to show all defaults.
@arimus arimus added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Apr 21, 2022
@BobFrankston
Copy link

This is frustrating because I can look at the log and find out the call stack, but it doesn't help me in fixing the problem. I accept that it's my error, but it would save many hours if there were more information about the source of the error.

In my case, I get Cannot read properties of null (reading 'package'). I'm using symbolic links, so there may be an inconsistency, but how can I find it? I can attach the log though I'm wary about posting specific info.

The line

37 verbose shrinkwrap failed to load node_modules/.package-lock.json missing from lockfile: ../mlib/node_modules/ansi-styles

hints at the problem but it works in other contexts

@silentcloud
Copy link

+1
node 16.15.1
npm 8.11.0

@lesliesu
Copy link

+1
node 16.13.2
npm 8.1.2

@AlekhyaYalla
Copy link

Any update on this issue? I'm facing this issue

@david-987
Copy link

+1 npm cache clear --force doesn't work which is my go-to when npm bugs out.
npm 8.1.4
node 16.14

@Zakyyy
Copy link

Zakyyy commented Jul 19, 2022

same

@jerinkalexander
Copy link

128 verbose node v16.15.1
129 verbose npm v8.14.0
130 error Cannot read properties of null (reading 'children')
131 verbose exit 1

Same here while running npm link.

@andrey-helldar
Copy link

andrey-helldar commented Jul 24, 2022

Node 16.16 and Npm 8.11 and 8.15 too

Show log
0 verbose cli C:\Users\Helldar\AppData\Local\nvs\default\node.exe C:\Users\Helldar\AppData\Local\nvs\default\node_modules\npm\bin\npm-cli.js
1 info using npm@8.11.0
2 info using node@v16.16.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 3ms
5 timing config:load:file:C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\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:D:\domains\volunteers\web\.npmrc Completed in 0ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:C:\Users\Helldar\.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:C:\Users\Helldar\AppData\Local\nvs\default\etc\npmrc Completed in 1ms
14 timing config:load:global Completed in 1ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:credentials Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 9ms
19 timing npm:load:configload Completed in 9ms
20 timing npm:load:mkdirpcache Completed in 1ms
21 timing npm:load:mkdirplogs Completed in 0ms
22 verbose title npm i
23 verbose argv "i"
24 timing npm:load:setTitle Completed in 1ms
25 timing config:load:flatten Completed in 2ms
26 timing npm:load:display Completed in 3ms
27 verbose logfile logs-max:10 dir:C:\Users\Helldar\AppData\Local\npm-cache\_logs
28 verbose logfile C:\Users\Helldar\AppData\Local\npm-cache\_logs\2022-07-24T10_07_31_732Z-debug-0.log
29 timing npm:load:logFile Completed in 3ms
30 timing npm:load:timers Completed in 0ms
31 timing npm:load:configScope Completed in 0ms
32 timing npm:load Completed in 17ms
33 timing arborist:ctor Completed in 0ms
34 silly logfile start cleaning logs, removing 1 files
35 silly logfile done cleaning log files
36 timing arborist:ctor Completed in 0ms
37 timing idealTree:init Completed in 9ms
38 timing idealTree:userRequests Completed in 0ms
39 silly idealTree buildDeps
40 silly fetch manifest @cloudgeek/vue3-video-player@^0.3.10
41 http fetch GET 200 https://registry.npmjs.org/@cloudgeek%2fvue3-video-player 300ms (cache miss)
42 silly fetch manifest @mdi/font@^6.2.0
43 http fetch GET 200 https://registry.npmjs.org/@mdi%2ffont 128ms (cache miss)
44 silly fetch manifest apexcharts@^3.35.3
45 http fetch GET 200 https://registry.npmjs.org/apexcharts 64ms (cache miss)
46 silly fetch manifest axios@^0.27.2
47 http fetch GET 200 https://registry.npmjs.org/axios 45ms (cache miss)
48 silly fetch manifest laravel-vue-i18n@^2.1.1
49 http fetch GET 200 https://registry.npmjs.org/laravel-vue-i18n 47ms (cache miss)
50 silly fetch manifest laravel-mix@^6.0.43
51 http fetch GET 200 https://registry.npmjs.org/laravel-mix 57ms (cache miss)
52 silly fetch manifest postcss@^8.4.14
53 http fetch GET 200 https://registry.npmjs.org/postcss 43ms (cache miss)
54 silly fetch manifest lodash@^4.17.21
55 http fetch GET 200 https://registry.npmjs.org/lodash 58ms (cache miss)
56 silly fetch manifest maska@^1.5.0
57 http fetch GET 200 https://registry.npmjs.org/maska 39ms (cache miss)
58 silly fetch manifest moment@^2.29.3
59 http fetch GET 200 https://registry.npmjs.org/moment 51ms (cache miss)
60 silly fetch manifest moment-duration-format@^2.3.2
61 http fetch GET 200 https://registry.npmjs.org/moment-duration-format 54ms (cache miss)
62 silly fetch manifest moment-timezone@^0.5.34
63 http fetch GET 200 https://registry.npmjs.org/moment-timezone 58ms (cache miss)
64 silly fetch manifest pinia@^2.0.14
65 http fetch GET 200 https://registry.npmjs.org/pinia 51ms (cache miss)
66 silly fetch manifest @vue/composition-api@^1.4.0
67 http fetch GET 200 https://registry.npmjs.org/@vue%2fcomposition-api 152ms (cache miss)
68 silly fetch manifest vue@^3.2.25
69 http fetch GET 200 https://registry.npmjs.org/vue 69ms (cache miss)
70 silly fetch manifest vue@>= 2.5 < 2.7
71 silly fetch manifest typescript@^4.5.4
72 http fetch GET 200 https://registry.npmjs.org/typescript 142ms (cache miss)
73 silly fetch manifest pinia-plugin-persistedstate@^1.6.3
74 http fetch GET 200 https://registry.npmjs.org/pinia-plugin-persistedstate 45ms (cache miss)
75 silly fetch manifest query-string@^7.1.1
76 http fetch GET 200 https://registry.npmjs.org/query-string 41ms (cache miss)
77 silly fetch manifest roboto-fontface@*
78 http fetch GET 200 https://registry.npmjs.org/roboto-fontface 42ms (cache miss)
79 silly fetch manifest vue-router@^4.0.16
80 http fetch GET 200 https://registry.npmjs.org/vue-router 54ms (cache miss)
81 silly fetch manifest vue-toastification@^2.0.0-rc.5
82 http fetch GET 200 https://registry.npmjs.org/vue-toastification 47ms (cache miss)
83 silly fetch manifest vue3-apexcharts@^1.4.1
84 http fetch GET 200 https://registry.npmjs.org/vue3-apexcharts 42ms (cache miss)
85 silly fetch manifest vue3-audio-player@^1.0.5
86 http fetch GET 200 https://registry.npmjs.org/vue3-audio-player 42ms (cache miss)
87 silly fetch manifest vue3-openlayers@^0.1.68
88 http fetch GET 200 https://registry.npmjs.org/vue3-openlayers 48ms (cache miss)
89 silly fetch manifest vue3-telegram-login@^0.0.4
90 http fetch GET 200 https://registry.npmjs.org/vue3-telegram-login 48ms (cache miss)
91 silly fetch manifest vuetify@^3.0.0-beta.5
92 http fetch GET 200 https://registry.npmjs.org/vuetify 62ms (cache miss)
93 silly fetch manifest @formatjs/intl@^1.0.0 || ^2.0.0
94 http fetch GET 200 https://registry.npmjs.org/@formatjs%2fintl 157ms (cache miss)
95 silly fetch manifest vite-plugin-vuetify@^1.0.0-alpha.0
96 http fetch GET 200 https://registry.npmjs.org/vite-plugin-vuetify 62ms (cache miss)
97 silly fetch manifest vite-plugin-vuetify@1.0.0-alpha.12
98 silly fetch manifest vite@^2.9.9
99 http fetch GET 200 https://registry.npmjs.org/vite 75ms (cache miss)
100 silly fetch manifest less@*
101 http fetch GET 200 https://registry.npmjs.org/less 49ms (cache miss)
102 silly fetch manifest sass@^1.53.0
103 http fetch GET 200 https://registry.npmjs.org/sass 53ms (cache miss)
104 silly fetch manifest stylus@*
105 http fetch GET 200 https://registry.npmjs.org/stylus 57ms (cache miss)
106 silly fetch manifest vue-i18n@^9.0.0
107 http fetch GET 200 https://registry.npmjs.org/vue-i18n 54ms (cache miss)
108 silly fetch manifest webpack-plugin-vuetify@2.0.0-alpha.11
109 http fetch GET 200 https://registry.npmjs.org/webpack-plugin-vuetify 77ms (cache miss)
110 silly fetch manifest @vue/compiler-sfc@^3.2.6
111 http fetch GET 200 https://registry.npmjs.org/@vue%2fcompiler-sfc 74ms (cache miss)
112 silly fetch manifest webpack@^5.0.0
113 http fetch GET 200 https://registry.npmjs.org/webpack 124ms (cache miss)
114 silly fetch manifest webfontloader@^1.0.0
115 http fetch GET 200 https://registry.npmjs.org/webfontloader 49ms (cache miss)
116 silly fetch manifest @babel/core@^7.18.6
117 http fetch GET 200 https://registry.npmjs.org/@babel%2fcore 57ms (cache miss)
118 silly fetch manifest @babel/plugin-proposal-class-properties@^7.18.6
119 http fetch GET 200 https://registry.npmjs.org/@babel%2fplugin-proposal-class-properties 52ms (cache miss)
120 silly fetch manifest @babel/plugin-proposal-optional-chaining@^7.18.6
121 http fetch GET 200 https://registry.npmjs.org/@babel%2fplugin-proposal-optional-chaining 58ms (cache miss)
122 silly fetch manifest @popperjs/core@^2.11.5
123 http fetch GET 200 https://registry.npmjs.org/@popperjs%2fcore 89ms (cache miss)
124 silly fetch manifest @types/lodash@^4.14.182
125 http fetch GET 200 https://registry.npmjs.org/@types%2flodash 63ms (cache miss)
126 silly fetch manifest @types/node@^18.0.5
127 http fetch GET 200 https://registry.npmjs.org/@types%2fnode 69ms (cache miss)
128 silly fetch manifest @types/webfontloader@^1.0.0
129 http fetch GET 200 https://registry.npmjs.org/@types%2fwebfontloader 66ms (cache miss)
130 silly fetch manifest @vitejs/plugin-vue@^2.3.3
131 http fetch GET 200 https://registry.npmjs.org/@vitejs%2fplugin-vue 89ms (cache miss)
132 silly fetch manifest autoprefixer@^10.4.7
133 http fetch GET 200 https://registry.npmjs.org/autoprefixer 56ms (cache miss)
134 silly fetch manifest eslint@^8.18.0
135 http fetch GET 200 https://registry.npmjs.org/eslint 48ms (cache miss)
136 silly fetch manifest eslint-plugin-prettier@^4.2.1
137 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-prettier 59ms (cache miss)
138 silly fetch manifest prettier@>=2.0.0
139 http fetch GET 200 https://registry.npmjs.org/prettier 63ms (cache miss)
140 silly fetch manifest eslint-plugin-you-dont-need-lodash-underscore@^6.12.0
141 http fetch GET 200 https://registry.npmjs.org/eslint-plugin-you-dont-need-lodash-underscore 45ms (cache miss)
142 silly fetch manifest postcss-import@^14.1.0
143 http fetch GET 200 https://registry.npmjs.org/postcss-import 42ms (cache miss)
144 silly fetch manifest vite@^2.7.0
145 silly fetch manifest sass@*
146 silly fetch manifest vuetify@^3.0.0-beta.4
147 silly fetch manifest typescript@^4.5
148 silly fetch manifest vue@^3.2.0
149 timing idealTree Completed in 3734ms
150 timing command:i Completed in 3743ms
151 verbose stack TypeError: Cannot read properties of null (reading 'explain')
151 verbose stack     at Arborist.[explainPeerConflict] (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1434:29)
151 verbose stack     at Arborist.[failPeerConflict] (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1427:44)
151 verbose stack     at Arborist.[loadPeerSet] (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1394:34)
151 verbose stack     at async Arborist.[buildDepStep] (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:976:11)
151 verbose stack     at async Arborist.buildIdealTree (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:218:7)
151 verbose stack     at async Promise.all (index 1)
151 verbose stack     at async Arborist.reify (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:153:5)
151 verbose stack     at async Install.exec (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\lib\commands\install.js:156:5)
151 verbose stack     at async module.exports (C:\Users\Helldar\AppData\Local\nvs\node\16.16.0\x64\node_modules\npm\lib\cli.js:78:5)
152 verbose cwd D:\domains\volunteers\web
153 verbose Windows_NT 10.0.22000
154 verbose node v16.16.0
155 verbose npm  v8.11.0
156 error Cannot read properties of null (reading 'explain')
157 verbose exit 1
158 timing npm Completed in 3831ms
159 verbose unfinished npm timer reify 1658657251816
160 verbose unfinished npm timer reify:loadTrees 1658657251822
161 verbose unfinished npm timer idealTree:buildDeps 1658657251833
162 verbose unfinished npm timer idealTree:#root 1658657251833
163 verbose code 1
164 error A complete log of this run can be found in:
164 error     C:\Users\Helldar\AppData\Local\npm-cache\_logs\2022-07-24T10_07_31_732Z-debug-0.log

@arimus
Copy link
Author

arimus commented Jul 26, 2022

This problem is super frustrating. I'm trying to get the package updated upstream, so that I no longer have a local file dependency, but that is taking a long time as well. Kind of surprised that more folks haven't been having this issue, which would give it more attention.

Worth noting that I've been playing with pnpm recently, which does not have this issue and also has a lot of good features. However, I did find some local relative path dependencies inside my tarball dep. That forced me to adjust to regular npm repo deps and rebuild the tarball, but that was pretty easy. Generally speaking, I'd love to just use npm straight up, but I may bite the bullet and start using pnpm (with shamefully-hoist :P for the time being).

Happy to re-test this when things are fixed though.

@ajibadeabd
Copy link

downgrade your node to 16.0, npm to 7+. this workes for me

@AnatuGreen
Copy link

Mine is this error:

npm ERR! Cannot read properties of null (reading 'children')

I have even uninstalled Node and reinstalled it. Same issue

@Zakyyy
Copy link

Zakyyy commented Aug 15, 2022

@AnatuGreen Can you try to install the dependencies from a terminal that opened with Rosetta (if you're using MacBook with M1 chip)
use node v16.16.0
npm v8

@AnatuGreen
Copy link

AnatuGreen commented Aug 15, 2022 via email

@BobFrankston
Copy link

BobFrankston commented Aug 15, 2022

As an FYI, my workaround is to delete or rename node_modules and then let npm install recreate it. I suspect problems in handling symlinks on Windows.

@Tauqeer180
Copy link

none of above Works

@ZackryPaul
Copy link

I have to install everything with --legacy-peer-deps

@AntreasPetsas
Copy link

AntreasPetsas commented Sep 19, 2022

downgrade to npm@7.0 fixed the issue. Just for the records I was using v8.19.2.
also worked by downgrading to 8.1.0.

@zanemcca
Copy link

zanemcca commented Oct 5, 2022

For those who have not found any of the previously mentioned solutions useful I found that adding a console.log(node) directly before the broken line at ...node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:718 to be very useful for debugging what was happening.

In my case I had a npm linked package in the package-lock that should have referenced the npm deployment of that dependency instead.

@heyakyra
Copy link

heyakyra commented Nov 22, 2022

Same here while running npm link

This happens if I use npm link with the package location on disk as a shortcut for cd [package-location]; npm link; cd [dependent project]; npm link [package-name]

If I instead link the package names, building my dependent project gives errors like Module not found: Error: Can't resolve '[package-name]/[module-name]' in '[dependent-project]'

Node v16.18.1 npm 9.1.2

@FlorianDevPhynix
Copy link

I was having the similar issue npm ERR! Cannot read properties of null (reading 'name')

my npm version was 8.19.2

upgrading to latest version, which was 9.2.0 at the time I was writing this, resolved this issue

@onorigin
Copy link

onorigin commented Jan 7, 2023

Same as above but 9.2.0 did not resolve it

@avidj
Copy link

avidj commented Jan 10, 2023

I get this when using npm workspaces.
npm 8.19.3
node 18.3.0

@jmni-cn
Copy link

jmni-cn commented Jan 19, 2023

上面的办法我都试了,可还是不能解决这个问题

@heyakyra
Copy link

heyakyra commented Feb 7, 2023

If I instead link the package names, building my dependent project gives errors like Module not found: Error: Can't resolve '[package-name]/[module-name]' in '[dependent-project]'

Node v16.18.1 npm 9.1.2

I have upgraded to Node v18.13.0 and npm 9.3.1 but still hit this issue

I no longer get a different error when symlinking the directory like npm link ../relative/path/to/package and instead get the same error as using the standard npm link; cd ../project; npm link package-name commands.

I have to install everything with --legacy-peer-deps

This had no effect

@StrixSC
Copy link

StrixSC commented Feb 10, 2023

Deleting node_modules/ worked for me.

@donworld
Copy link

+1
node 16.14.1
npm 8.19.2

downgrade npm to 8.1.0 worked for me

@CodyKlimkofski
Copy link

+1
node 16.19.1
npm 9.4.2

@fifkapetr
Copy link

fifkapetr commented May 9, 2023

+1
node v18.16.0
npm 9.6.6

Prompt: npm install styled-components
ERR:

 01-starting-project 2 git:(accounts) ✗ npm install styled-components 
npm ERR! Cannot read properties of null (reading 'edgesOut')

npm ERR! A complete log of this run can be found in: /Users/petrfifka/.npm/_logs/2023-05-09T11_02_05_183Z-debug-0.log

2023-05-09T11_02_05_183Z-debug-0.log

EDIT: downgrade to 8.1.0 didn't work. I needed to downgrade to 7.7.6

@KCmean
Copy link

KCmean commented May 10, 2023

even I am having the same error while installing styled components.
I tried downloading the version too, but it didn't help.

@manikanda-s
Copy link

try this --> npm install styled-components@5.3.10

it works :-)

@hanleymark
Copy link

npm install styled-components@latest <--- worked for me

haneenmahd added a commit to haneenmahd/cli that referenced this issue Jun 23, 2023
@haneenmahd haneenmahd linked a pull request Jun 23, 2023 that will close this issue
@vaesonshu
Copy link

vaesonshu commented Jul 7, 2023

I tried delete package-lock.json and npm install again, Solved my problem.

@mhadad
Copy link

mhadad commented Jul 21, 2023

npm install styled-components@latest

it should be
npm install -g styled-components@latest

@kashif-ghafoor
Copy link

kashif-ghafoor commented Sep 9, 2023

I encountered this error when using npm link, and I'd like to share the solution that worked for me.

Solution:
The error arises when running npm link multiple times.

When you initially run npm link in the root folder of your project, it creates a symbolic link in the global packages. You can check the global packages using npm ls -g.

If you need to run npm link again, you may encounter this error. To resolve it, follow these steps:

a. First, you should unlink the package using npm unlink <package-name>.

b. After unlinking, you can run npm link again without any issues.

@trusktr
Copy link

trusktr commented Oct 14, 2023

I just encountered this issue with npm 10.1.0. I didn't try downgrading to 9.0.

This is the error

60 verbose stack TypeError: Cannot read properties of null (reading 'package')
60 verbose stack     at set root [as root] (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:746:35)
60 verbose stack     at set root [as root] (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:812:20)
60 verbose stack     at set root [as root] (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:820:19)
60 verbose stack     at set root [as root] (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:812:20)
60 verbose stack     at Node.replace (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:1173:26)
60 verbose stack     at PlaceDep.replaceOldDep (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:387:17)
60 verbose stack     at new PlaceDep (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:256:12)
60 verbose stack     at #buildDepStep (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:933:18)
60 verbose stack     at async Arborist.buildIdealTree (/Users/trusktr/.npm-packages/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:196:7)
60 verbose stack     at async Promise.all (index 1)

In my case, I deleted node_modules and then tried what I was previously trying, and it worked.

I'm also using Lerna, but I haven't had this issue before. Many people above said this has to do with linked dependencies, and Lerna is in fact linking dependencies from all of my git submodules together. So it seems that linking might have to do with the issue.

@trusktr
Copy link

trusktr commented Oct 24, 2023

In a project that's a git submodule and workspace in a parent repo, I had to delete node_modules and run npm install --no-workspaces for the install to succeed.

I'm guessing this means that running plain npm install in the git submodule traverses upward, and interacts with workspaces outside of the project, and these workspaces have been linked with yarn.

This is painful. Really hoping this can be fixed.

trusktr added a commit to lume/cli that referenced this issue Nov 5, 2023
…rettier'

* remove-global-builds-switch-to-web-test-runner-update-prettier: (29 commits)
  feat: fallback to loading jest globals in test-runner from the hoisted node_modules location if it is not located in lume/cli's node_modules
  BREAKING: add a check to ensure that the repo is not modified before versioning during release. Repo author should be sure to commit build outputs, or fix the build so no changes happen during build that are not tracked.
  undo testing in firefox and safari for now, some lume code needs fixing
  BREAKING: besides Chromium, also run tests in Firefox and Safari in CI. Migration: If you didn't test those browsers before, you might have to update any code that is not compatible. Alternatively, make sure there is no CI env var set and it will test in Chrome only.
  update test-runner port range to avoid ports denylisted by Chrome
  install web test-runner's playwright launcher, and use that to run tests in Chrome in CI
  run tests on a random port to avoid collisions when running tests in parallel for multiple projects at the same time
  BREAKING: migrate from Karma to `@web/test-runner`. This removed a lot of dependencies (namely Webpack needed for the Karma setup), greatly reduces maintenance burden, speeds tests up, provides a much simpler and better test development and debugging experience with minimal configuration compared to with Karma, and ensures longevity of test code by ensuring that they run as standard JavaScript modules. 🎉 The `webpackConfigs` and `testSpecFormat` options for `lume.config.cjs` have been removed. Migration: Delete any webpack configs, all code should be vanilla JavaScript (ES) modules. There is only one test spec format now (Mocha `describe()`/`it()` and Jest `expect()`). Test syntax is mostly the same, and most tests will remain as-is. A few things need to be changed from Jasmine's `expect()` API to Jest's very similar `expect()` API. For example, `expect(true).toBeTrue()` needs to be changed to `expect(true).toBe(true)`. `jasmine.*` API is removed, f.e. `jasmine.createSpy` can be replaced with `sinon.spy()`. Try running tests, see what broke, then look up the way to do it with Jest or with Sinon, etc. Also tests are executed as vanilla ES Modules in a browser, and an `importMap` field will need to be defined in `lume.config.js` to handle bare specifiers (f.e. the `foo` in `import something from 'foo'`). Only ES Modules are supported, so if any libraries are CommonJS, those will not work and alternatives will be needed. The CLI can be forked though, and `@web/test-runner`'s config can be expanded to use its built-in `esbuild` plugin, along with Rollup plugins for any non-vanilla-ESM use cases.
  BREAKING: instead of trying to stash changes and continuing with versioning and publishing, exit non-zero if the working directory is dirty. Migration: clear your git repo of changes, then try again.
  update version scripts to avoid an issue with workspaces and linked dependencies (npm/cli#5687, npm/cli#4787)
  BREAKING: remove the global build feature, from now on we output and publish only JS modules for simplicity. Migration: @lume/cli will no longer output global.js files for use with non-module script tags, instead any code depending on your @lume/cli-managed package should use `import` syntax to import your package.
  port karma bash script to Node so it works in Windows too
  ensure line endings match with the rest of our tooling (all work in LF)
  ensure that we also get tsc, babel, and prettier bins with Node module lookup to avoid relying on PATH (Yarn and NPM set PATH differently, see Yarn issue 5800)
  update exec calls to find binaries using node_module resolution instead of relying on PATH to prevent cross-platform issues with Windows, and make the noFailOnError option use || echo '' instead of || true for cross-platform support
  prevent duplicate solid-js libs. Its ok to hard code this one case, because solid-js is a key dependency of lume
  Avoid error with fs.mkdir if dir already exists. Why is it so difficult?
  ensure dist/ is created before we copy assets to hopefully solve a problem with this in Windows CI (https://github.com/lume/lume/actions/runs/6519881972/job/17706893670)
  update prettier to 3.0.3
  infra: add .gitattributes with rules to enforce that code is checked out with LF line endings only, which prevents Prettier from failing in Windows
  ...
@BobFrankston
Copy link

This is still happening in Windows but not DSL. How can I trace it down? The problem shows up long after the root cause making it hard for me to trace the problem back.

npm versions
Windows 10.2.0
WSL 10.2.4

@lukekarrys lukekarrys added Priority 1 high priority issue Release 9.x work is associated with a specific npm 9 release Release 10.x and removed Needs Triage needs review for next steps labels Dec 6, 2023
@lukekarrys lukekarrys self-assigned this Dec 6, 2023
@mwe
Copy link

mwe commented Jan 26, 2024

I just encountered this issue with npm 10.1.0. I didn't try downgrading to 9.0.

This is the error

60 verbose stack TypeError: Cannot read properties of null (reading 'package')
In my case, I deleted `node_modules` and then tried what I was previously trying, and it worked.

If this does not resolve it, also deleting the package.lock.json resolves it, it seems also to be related by a package.lock.json that is not matching the current dependency tree in relation with symlinks

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

Successfully merging a pull request may close this issue.