Cannot read properties of null (reading 'pickAlgorithm')

环境

  • win10
  • node v18.4.0
  • npm 8.12.1

问题

今天checkout了一个node工程,执行npm ci的时候,出现了如下错误:

npm WARN deprecated @types/[email protected]: This is a stub types definition for Moment (https://github.com/moment/moment). Moment provides its own type definitions, so you don't need @types/moment installed!
npm WARN deprecated @types/[email protected]: This is a stub types definition for xlsx (https://github.com/sheetjs/js-xlsx). xlsx provides its own type definitions, so you don't need @types/xlsx installed!
npm WARN deprecated @types/[email protected]: This is a stub types definition for commander (https://github.com/tj/commander.js). commander provides its own type definitions, so you don't need @types/commander installed!
npm WARN deprecated [email protected]: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
npm ERR! Cannot read properties of null (reading 'pickAlgorithm')

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\admin\AppData\Local\npm-cache\_logs\2022-08-16T11_02_33_201Z-debug-0.log

查看项目下,没有node_modules文件夹。很明显,安装失败。

解决过程

先直接百度,有人说执行npm cache clear --force就好了。
回想一下,我checkout下来后,第一次执行npm ci时曾经ctrl c中止过,可能缓存有问题,这个方法似乎很合理。试了一下,Not works for me.
那就老老实实打开日志看看吧,最直接的错误是

143 verbose stack TypeError: Cannot read properties of null (reading 'pickAlgorithm')
143 verbose stack     at Integrity.match (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\ssri\lib\index.js:273:24)
143 verbose stack     at CachePolicy.satisfies (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\make-fetch-happen\lib\cache\policy.js:112:49)
143 verbose stack     at CacheEntry.find (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\make-fetch-happen\lib\cache\entry.js:177:25)
143 verbose stack     at async cacheFetch (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\make-fetch-happen\lib\cache\index.js:8:17)
143 verbose stack     at async fetch (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\make-fetch-happen\lib\fetch.js:98:7)
144 verbose cwd G:\tgit\smarttalk\tools\spider
145 verbose Windows_NT 10.0.19043
146 verbose node v18.4.0
147 verbose npm  v8.12.1
148 error Cannot read properties of null (reading 'pickAlgorithm')
149 verbose exit 1
150 timing npm Completed in 10574ms
151 verbose unfinished npm timer reify 1660647753530
152 verbose unfinished npm timer reify:unpack 1660647753597
153 verbose unfinished npm timer reifyNode:node_modules/util-deprecate 1660647753598
154 verbose unfinished npm timer reifyNode:node_modules/methods 1660647753600
155 verbose unfinished npm timer reifyNode:node_modules/delayed-stream 1660647753601
156 verbose unfinished npm timer reifyNode:node_modules/asynckit 1660647753602
157 verbose code 1
158 error A complete log of this run can be found in:
158 error     C:\Users\admin\AppData\Local\npm-cache\_logs\2022-08-16T11_02_33_201Z-debug-0.log

这个看不出来问题所在,再往上翻一翻,可以看到404错误

63 http fetch POST 404 https://registry.npmmirror.com/-/npm/v1/security/audits/quick 66ms (cache skip)
64 verbose audit error HttpErrorGeneral: 404 Not Found - POST https://registry.npmmirror.com/-/npm/v1/security/audits/quick
64 verbose audit error     at C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\npm-registry-fetch\lib\check-response.js:93:15
64 verbose audit error     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
64 verbose audit error     at async [getReport] (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\audit-report.js:333:21)
64 verbose audit error     at async AuditReport.run (C:\Users\admin\AppData\Local\nvs\node\18.4.0\x64\node_modules\npm\node_modules\@npmcli\arborist\lib\audit-report.js:106:19) {
64 verbose audit error   headers: [Object: null prototype] {
64 verbose audit error     server: [ 'Tengine' ],
64 verbose audit error     'content-type': [ 'text/html; charset=utf-8' ],
64 verbose audit error     'content-length': [ '41' ],
64 verbose audit error     connection: [ 'keep-alive' ],
64 verbose audit error     'strict-transport-security': [ 'max-age=5184000' ],
64 verbose audit error     date: [ 'Tue, 16 Aug 2022 11:02:33 GMT' ],
64 verbose audit error     vary: [ 'Origin' ],
64 verbose audit error     'x-frame-options': [ 'SAMEORIGIN' ],
64 verbose audit error     'x-xss-protection': [ '1; mode=block' ],
64 verbose audit error     'x-content-type-options': [ 'nosniff' ],
64 verbose audit error     'x-download-options': [ 'noopen' ],
64 verbose audit error     'x-readtime': [ '0.947' ],
64 verbose audit error     'content-encoding': [ 'gzip' ],
64 verbose audit error     'ali-swift-global-savetime': [ '1660647753' ],
64 verbose audit error     via: [
64 verbose audit error       'cache15.l2cn1851[35,35,404-1280,M], cache3.l2cn1851[36,0], kunlun9.cn1361[0,0,404-0,H], kunlun8.cn1361[2,0]'
64 verbose audit error     ],
64 verbose audit error     age: [ '0' ],
64 verbose audit error     'x-cache': [ 'HIT TCP_MEM_HIT dirn:-2:-2' ],
64 verbose audit error     'x-swift-savetime': [ 'Tue, 16 Aug 2022 11:02:33 GMT' ],
64 verbose audit error     'x-swift-cachetime': [ '1' ],
64 verbose audit error     'timing-allow-origin': [ '*' ],
64 verbose audit error     eagleid: [ 'b706e79c16606477534711042e' ],
64 verbose audit error     'x-fetch-attempts': [ '1' ],
64 verbose audit error     'x-local-cache-status': [ 'skip' ]
64 verbose audit error   },
64 verbose audit error   statusCode: 404,
64 verbose audit error   code: 'E404',
64 verbose audit error   method: 'POST',
64 verbose audit error   uri: 'https://registry.npmmirror.com/-/npm/v1/security/audits/quick',
64 verbose audit error   body: ,
64 verbose audit error   pkgid: undefined
64 verbose audit error }
65 silly audit error 

404 Not Found

意思应该是镜像获取不到,输入命令npm config get registry,看到自己确实使用了taobao镜像

G:\tgit\smarttalk\tools\spider>npm config get registry
https://registry.npmjs.org/

执行以下命令取消镜像:npm config delete registry
再试一下,没问题了~

你可能感兴趣的:(Cannot read properties of null (reading 'pickAlgorithm'))