.git can't be found during prepare
在 Bigtop 编译 Flink Dashboard 模块时,执行 npm install
过程中触发了 husky install
脚本,但由于构建目录并不包含 .git
,导致报错退出。
# 报错日志详解
日志如下:
npm info lifecycle flink-dashboard@2.0.0~prepublish: flink-dashboard@2.0.0
npm info lifecycle flink-dashboard@2.0.0~prepare: flink-dashboard@2.0.0
npm WARN lifecycle The node binary used for scripts is /root/.nvm/versions/node/v12.13.0/bin/node but npm is using /opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-w
eb/web-dashboard/node/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> flink-dashboard@2.0.0 prepare /opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard
> cd ../.. && husky install flink-runtime-web/web-dashboard/.husky
.git can't be found (see https://git.io/Jc3F9)
npm verb lifecycle flink-dashboard@2.0.0~prepare: unsafe-perm in lifecycle true
npm verb lifecycle flink-dashboard@2.0.0~prepare: PATH: /opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/node/node_modules/npm/node_modules/npm-lif
ecycle/node-gyp-bin:/opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/node_modules/.bin:/root/.nvm/versions/node/v12.13.0/bin:/opt/enhance_env/minic
onda2/bin:/opt/enhance_env/miniconda2/condabin:/opt/enhance_env/flex-2.6.4/bin:/usr/local/R-4.4.2/bin:/opt/modules/cmake3/bin:/opt/modules/apache-maven-3.8.4/bin:/usr
/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/modules/jdk1.8.0_202/bin:/opt/modules/gradle-5.6.4/bin:/opt/modules/apache-ant-1.10.12
/bin:/opt/modules/apache-ivy-2.5.0/bin
npm verb lifecycle flink-dashboard@2.0.0~prepare: CWD: /opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard
npm info lifecycle flink-dashboard@2.0.0~prepare: Failed to exec prepare script
npm verb stack Error: flink-dashboard@2.0.0 prepare: `cd ../.. && husky install flink-runtime-web/web-dashboard/.husky`
npm verb stack Exit status 1
npm verb stack at EventEmitter.<anonymous> (/opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/node/node_modules/npm/node_modules/npm-lifecycle/i
ndex.js:332:16)
npm verb stack at EventEmitter.emit (events.js:314:20)
npm verb stack at ChildProcess.<anonymous> (/opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/node/node_modules/npm/node_modules/npm-lifecycle/l
ib/spawn.js:55:14)
npm verb stack at ChildProcess.emit (events.js:314:20)
npm verb stack at maybeClose (internal/child_process.js:1022:16)
npm verb stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
npm verb pkgid flink-dashboard@2.0.0
npm verb cwd /opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard
npm verb Linux 5.15.167.4-microsoft-standard-WSL2
npm verb argv "/opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/node/node" "/opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/nod
e/node_modules/npm/bin/npm-cli.js" "install" "--unsafe-perm" "--verbose" "--save" "--progress" "--registry=https://registry.npmmirror.com/"
npm verb node v12.22.6
npm verb npm v6.14.5
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! flink-dashboard@2.0.0 prepare: `cd ../.. && husky install flink-runtime-web/web-dashboard/.husky`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the flink-dashboard@2.0.0 prepare script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 1, true ]
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
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
典型症状
husky 的 prepare 阶段试图执行 husky install
,但当前目录并不是 Git 仓库,触发错误。
此外,还伴随 Node.js 路径混乱警告:
npm WARN lifecycle The node binary used for scripts is /root/.nvm/versions/node/v12.13.0/bin/node
but npm is using /opt/modules/bigtop/dl/flink-1.17.2/flink-runtime-web/web-dashboard/node/node itself.
1
2
2
参数 --scripts-prepend-node-path
可以指定使用 nvm 下 Node 路径,避免路径错乱。建议添加
# 报错截图参考
构建失败输出如下:
通过 npm install
安装依赖时直接中断:
# 解决方案:跳过脚本执行
构建场景中我们并不需要 husky
,因此建议显式跳过:
# 添加 --ignore-scripts
参数
npm install --unsafe-perm --verbose --save --progress --ignore-scripts
1
修改代码如下:
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<!--<arguments>ci --cache-max=0 --no-save ${npm.proxy}</arguments> -->
<arguments>install --unsafe-perm --verbose --save --progress --ignore-scripts</arguments>
<npmRegistryURL>https://registry.npmmirror.com/</npmRegistryURL>
<environmentVariables>
<HUSKY_SKIP_INSTALL>true</HUSKY_SKIP_INSTALL>
</environmentVariables>
</configuration>
</execution>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15