0%

npm技法总结

npm

作为前端的优秀包管理工具,记录一下

shell命令

install

force

将所有的包重新安装,太多包的话很危险,慎用

运行script

若有package.json

1
2
3
4
5
6
7
8
"scripts": {
"clean": "hexo clean",
"deploy": "hexo deploy",
"server": "hexo server",
"build": "hexo generate && node gittalk-auto-init.js",
"talk": "node gittalk-auto-init.js",
"merge": "cd python && python app.py"
},

npm run merge 运行对应的代码

node安装

官网下载源码,解压

ln -s /app/software/nodejs/bin/npm /usr/local/bin/

ln -s /app/software/nodejs/bin/node /usr/local/bin/

bug

global hexo cli不能用

代码详情
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Microsoft Windows [版本 10.0.19043.985]
(c) Microsoft Corporation。保留所有权利。

D:\ednow\blog>hexo
ERROR Cannot find module 'hexo' from 'D:\ednow\blog'
ERROR Local hexo loading failed in D:\ednow\blog
ERROR Try running: 'rm -rf node_modules && npm install --force'

D:\ednow\blog>cd /

D:\>hexo
Usage: hexo <command>

Commands:
help Get help on a command.
init Create a new Hexo folder.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

D:\>cd ednow

D:\ednow>cd blog

D:\ednow\blog>npm install hexo
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated ejs@1.0.0: Critical security bugs fixed in 2.5.5
npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
npm ERR! code 1
npm ERR! path D:\ednow\blog\node_modules\canvas
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! Warning: Missing input files:
npm ERR! C:\GTK\bin\libcairo-2.dll
npm ERR! C:\GTK\bin\libgobject-2.0-0.dll
npm ERR! C:\GTK\bin\libpangoft2-1.0-0.dll
npm ERR! C:\GTK\bin\libfontconfig-1.dll
npm ERR! C:\GTK\bin\libpangowin32-1.0-0.dll
npm ERR! C:\GTK\bin\libfreetype-6.dll
npm ERR! C:\GTK\bin\zlib1.dll
npm ERR! C:\GTK\bin\libglib-2.0-0.dll
npm ERR! C:\GTK\bin\libpangocairo-1.0-0.dll
npm ERR! C:\GTK\bin\libgthread-2.0-0.dll
npm ERR! C:\GTK\bin\libintl-8.dll
npm ERR! C:\GTK\bin\libgmodule-2.0-0.dll
npm ERR! C:\GTK\bin\libpango-1.0-0.dll
npm ERR! C:\GTK\bin\libpng14-14.dll
npm ERR! C:\GTK\bin\libexpat-1.dll
npm ERR! �ڴ˽��������һ������һ����Ŀ����Ҫ���ò������ɣ������ӡ�-m�����ء�
npm ERR! Backend.cc
npm ERR! D:\ednow\blog\node_modules\canvas\src\backend\Backend.h(3,10): fatal error C1083: �޷��򿪰����ļ�: ��c airo.h��: No such file or directory [D:\ednow\blog\node_modules\canvas\build\canvas.vcxproj]
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@14.17.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.8.10 found at "C:\Users\46257\AppData\Local\Programs\Python\Python38\python.exe"
npm ERR! gyp http GET https://nodejs.org/download/release/v14.17.0/node-v14.17.0-headers.tar.gz
npm ERR! gyp http 200 https://nodejs.org/download/release/v14.17.0/node-v14.17.0-headers.tar.gz
npm ERR! gyp http GET https://nodejs.org/download/release/v14.17.0/SHASUMS256.txt
npm ERR! gyp http GET https://nodejs.org/download/release/v14.17.0/win-x64/node.lib
npm ERR! gyp http GET https://nodejs.org/download/release/v14.17.0/win-x86/node.lib
npm ERR! gyp http GET https://nodejs.org/download/release/v14.17.0/win-arm64/node.lib
npm ERR! gyp http 200 https://nodejs.org/download/release/v14.17.0/win-x86/node.lib
npm ERR! gyp http 200 https://nodejs.org/download/release/v14.17.0/SHASUMS256.txt
npm ERR! gyp http 404 https://nodejs.org/download/release/v14.17.0/win-arm64/node.lib
npm ERR! gyp http 200 https://nodejs.org/download/release/v14.17.0/win-x64/node.lib
npm ERR! gyp info find VS using VS2019 (16.10.31410.357) found at:
npm ERR! gyp info find VS "D:\Microsoft Visual Studio\2019\Enterprise"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Users\46257\AppData\Local\Programs\Python\Python38\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'msvs',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'D:\\ednow\\blog\\node_modules\\canvas\\build\\config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'C:\\Users\\46257\\AppData\\Local\\node-gyp\\Cache\\14.17.0\\include\\node\\common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=C:\\Users\\46257\\AppData\\Local\\node-gyp\\Cache\\14.17.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\46257\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\14.17.0\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=D:\\ednow\\blog\\node_modules\\canvas',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'D:\\ednow\\blog\\node_modules\\canvas\\build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn D:\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'build/binding.sln',
npm ERR! gyp info spawn args '/clp:Verbosity=minimal',
npm ERR! gyp info spawn args '/nologo',
npm ERR! gyp info spawn args '/p:Configuration=Release;Platform=x64'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `D:\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onExit (C:\Users\46257\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:376:20)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19043
npm ERR! gyp ERR! command "D:\\nodejs\\node.exe" "C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\ednow\blog\node_modules\canvas
npm ERR! gyp ERR! node -v v14.17.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\46257\AppData\Local\npm-cache\_logs\2021-09-12T01_00_39_630Z-debug.log

D:\ednow\blog>hexo
ERROR Cannot find module 'hexo' from 'D:\ednow\blog'
ERROR Local hexo loading failed in D:\ednow\blog
ERROR Try running: 'rm -rf node_modules && npm install --force'

D:\ednow\blog>npm install
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated ejs@1.0.0: Critical security bugs fixed in 2.5.5
npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
npm WARN deprecated highlight.js@9.18.5: Support has ended for 9.x series. Upgrade to @latest
npm ERR! code 1
npm ERR! path D:\ednow\blog\node_modules\canvas
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! Warning: Missing input files:
npm ERR! C:\GTK\bin\libgthread-2.0-0.dll
npm ERR! C:\GTK\bin\zlib1.dll
npm ERR! C:\GTK\bin\libintl-8.dll
npm ERR! C:\GTK\bin\libfontconfig-1.dll
npm ERR! C:\GTK\bin\libgmodule-2.0-0.dll
npm ERR! C:\GTK\bin\libpng14-14.dll
npm ERR! C:\GTK\bin\libgobject-2.0-0.dll
npm ERR! C:\GTK\bin\libexpat-1.dll
npm ERR! C:\GTK\bin\libpango-1.0-0.dll
npm ERR! C:\GTK\bin\libpangocairo-1.0-0.dll
npm ERR! C:\GTK\bin\libpangowin32-1.0-0.dll
npm ERR! C:\GTK\bin\libpangoft2-1.0-0.dll
npm ERR! C:\GTK\bin\libcairo-2.dll
npm ERR! C:\GTK\bin\libfreetype-6.dll
npm ERR! C:\GTK\bin\libglib-2.0-0.dll
npm ERR! �ڴ˽��������һ������һ����Ŀ����Ҫ���ò������ɣ������ӡ�-m�����ء�
npm ERR! Backend.cc
npm ERR! D:\ednow\blog\node_modules\canvas\src\backend\Backend.h(3,10): fatal error C1083: �޷��򿪰����ļ�: ��c airo.h��: No such file or directory [D:\ednow\blog\node_modules\canvas\build\canvas.vcxproj]
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@14.17.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.8.10 found at "C:\Users\46257\AppData\Local\Programs\Python\Python38\python.exe"
npm ERR! gyp info find VS using VS2019 (16.10.31410.357) found at:
npm ERR! gyp info find VS "D:\Microsoft Visual Studio\2019\Enterprise"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Users\46257\AppData\Local\Programs\Python\Python38\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'msvs',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'D:\\ednow\\blog\\node_modules\\canvas\\build\\config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'C:\\Users\\46257\\AppData\\Local\\node-gyp\\Cache\\14.17.0\\include\\node\\common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=C:\\Users\\46257\\AppData\\Local\\node-gyp\\Cache\\14.17.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\46257\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\14.17.0\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=D:\\ednow\\blog\\node_modules\\canvas',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'D:\\ednow\\blog\\node_modules\\canvas\\build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn D:\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'build/binding.sln',
npm ERR! gyp info spawn args '/clp:Verbosity=minimal',
npm ERR! gyp info spawn args '/nologo',
npm ERR! gyp info spawn args '/p:Configuration=Release;Platform=x64'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `D:\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onExit (C:\Users\46257\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:376:20)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19043
npm ERR! gyp ERR! command "D:\\nodejs\\node.exe" "C:\\Users\\46257\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\ednow\blog\node_modules\canvas
npm ERR! gyp ERR! node -v v14.17.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\46257\AppData\Local\npm-cache\_logs\2021-09-12T01_04_36_549Z-debug.log

D:\ednow\blog>hexo new post
ERROR Cannot find module 'hexo' from 'D:\ednow\blog'
ERROR Local hexo loading failed in D:\ednow\blog
ERROR Try running: 'rm -rf node_modules && npm install --force'

D:\ednow\blog>