摘要: 今天尝试建立 OpenLayers 页面,参考 https://openlayers.org/doc/quickstart.html ,看起来应该是比较简单。这个页面中创建项目的命令为: npm create ol-app my-app 现在都是用容器来执行...
今天尝试建立 OpenLayers 页面,参考 https://openlayers.org/doc/quickstart.html ,看起来应该是比较简单。这个页面中创建项目的命令为:
npm create ol-app my-app
现在都是用容器来执行nodejs环境,使用以下命令:
podman run --rm -it -v `pwd`:/ws node:lts-alpine sh -c 'cd /ws && npm create ol-app my-app'
但是出错了,结果如下:
could not find commit hash for HEAD
npm ERR! code 1
npm ERR! path /ws
npm ERR! command failed
npm ERR! command sh -c -- create-ol-app my-app
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-10-27T13_57_37_772Z-debug-0.log
在网上找资料解决,有一个是说需要用普通用户来执行node命令,这个还真有点麻烦,得自行构建镜像。
继续找,发现这个: https://github.com/openlayers/openlayers/issues/12860 , 是说需要系统中安装有 git
工具。
以前用容器来运行相关命令大都基于 Debian , 都已经安装有 git
工具,还真没想到是这个问题。
这里运行的是官方的镜像,基于 Alpine 操作系统。进一步学习其安装 git
的命令:
# apk 仓库更新
apk update
# 安装 git
apk add git
然后再创建 OpenLayers 项目。这次没有问题,成功创建。