虚拟机的linux、nodejs和npm相关参数为
$ uname -a
Linux ubuntu 5.13.0-44-generic #49~20.04.1-Ubuntu SMP Wed May 18 18:44:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ node -v
v16.14.2
$ npm -v
8.5.0
安装pinyin版本为2.11.2,本地调试没啥问题,开发好的程序通过云效用docker部署到服务器,但是cnpm i会报错。内容如下:
[16:51:39] node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/root/workspace/basicGoods_Ggrl/node_modules/_@mapbox_node-pre-gyp@1.0.9@@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
[16:51:39] node-pre-gyp ERR! stack at ChildProcess.emit (node:events:527:28)
[16:51:39] node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1092:16)
[16:51:39] node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
[16:51:39] node-pre-gyp ERR! System Linux 3.10.0-1160.15.2.el7.x86_64
[16:51:39] node-pre-gyp ERR! command "/root/.nvm/versions/node/v16.15.1/bin/node" "/root/workspace/basicGoods_Ggrl/node_modules/_nodejieba@2.5.2@nodejieba/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
[16:51:39] node-pre-gyp ERR! cwd /root/workspace/basicGoods_Ggrl/node_modules/_nodejieba@2.5.2@nodejieba
[16:51:39] node-pre-gyp ERR! node -v v16.15.1
[16:51:39] node-pre-gyp ERR! node-pre-gyp -v v1.0.9
[16:51:39] node-pre-gyp ERR! not ok
后来查找发现是此问题
[16:51:28] npm info using npm@8.11.0
[16:51:28] npm info using node@v16.15.1
降node版本为14即可通过。
在下一步读取Dockerfile安装依赖时还是无法通过
FROM node:16-alpine AS build
发现是要选14-alpine,修改就可以构建成功了。
最后请求接口时,发现使用了pinyin的接口,一请求,整个docker就会退出。
找来找去,发现pinyin包中的segment参数设置为true,改成false就没问题了。但是有些场景还是会使用true的情况,怎么办?暂时还没找到解决方法。