昨夜C盘爆满,操作清浊清理缓存没有注意选项一股脑全删了,今天用npm的时候发现前端的那些包管理器通通失效!!

:sob:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
E:\Blog_Butterfly>hexo n 清除缓存把npm给清理了
node:internal/modules/cjs/loader:1222
throw err;
^

Error: Cannot find module 'E:\nodejs\node_global\node_modules\hexo-cli\bin\hexo'
at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)
at Module._load (node:internal/modules/cjs/loader:1045:27)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:158:5)
at node:internal/main/run_main_module:30:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Node.js v22.4.0

E:\Blog_Butterfly>cnpm -v
node:internal/modules/cjs/loader:1222
throw err;
^

Error: Cannot find module 'E:\nodejs\node_global\node_modules\cnpm\bin\cnpm.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)
at Module._load (node:internal/modules/cjs/loader:1045:27)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:158:5)
at node:internal/main/run_main_module:30:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

Node.js v22.4.0

解决办法很简答,把目录下的文件全给删了

image-20240703010529504

再把项目的中的依赖也删了就能重新使用了,比如:

1
2
3
4
5
$ hexo
ERROR Cannot find module 'hexo' from 'E:\Blog_Butterfly'
ERROR Local hexo loading failed in E:\Blog_Butterfly
ERROR Try running: 'rm -rf node_modules && npm install --force'

删除模块并重新安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Yee@Yee MINGW64 /e/Blog_Butterfly
$ rm -rf node_modules
npm install --force
npm warn using --force Recommended protections disabled.
npm warn deprecated cuid@2.1.8: Cuid and other k-sortable and non-cryptographic ids (Ulid, ObjectId, KSUID, all UUIDs) are all insecure. Use @paralleldrive/cuid2 instead.
npm warn deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest

added 270 packages in 5s

Yee@Yee MINGW64 /e/Blog_Butterfly
$ npm install -g hexo-cli

changed 53 packages in 3s

14 packages are looking for funding
run `npm fund` for details

启动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Yee@Yee MINGW64 /e/Blog_Butterfly
$ hexo -v
INFO Validating config
INFO
===================================================================
##### # # ##### ##### ###### ##### ###### # # #
# # # # # # # # # # # # #
##### # # # # ##### # # ##### # #
# # # # # # # ##### # # #
# # # # # # # # # # # #
##### #### # # ###### # # # ###### #
4.11.0
===================================================================

好多个模块一个一个安装…好繁琐的程序啊