由于Sharp基于C++的libvips库来实现,本地Mac开发完后在部署时安装sharp模块时会基于测试环境Liunx平台编译安装,测试环境安装时发现请求github下载libvips-8.9.1-linux-x64.tar.gz,所以只能失败告终。后来看源码和文档发现sharp项目考虑周到优先使用缓存和使用sharp_dist_base_url参数,这样可以先将libvips-8.9.1-linux-x64.tar.gz下载到内网。npm缓存路径使用npm config get cache 查询。新建_libvips,把libvips-8.9.0-linux-x64.tar.gz放进去。Using cached /root/.npm/_libvips/libvips-8.9.0-linux-x64.tar.gz,这样安装时就不会再请求了。npm config set sharp_dist_base_url "https://hostname/path/"npm config set sharp_dist_base_url "https://hostname/path/"https://hostname/path/或者 SHARP_DIST_BASE_URL=http://172.20.x.x npm i --unsafe-perm --allow-root表面上看使用以上方法解决请求不到依赖包的问题事情就搞定了,但远没这么简单。由于需要Liunx环境来安装编译sharp,自然想到用虚拟机或Docker,通过Parallels Desktop安装下载好的CentOS-8.1.1911-x86_64-boot.iso,提示无法识别镜像,没道理啊。后来多次尝试发现可选择其它选择中的默认Linux来安装但启动不了系统,研究一翻把CD-ROM启动指向到CentOS-8.1.1911-x86_64-boot.iso重启就能使用CDROM来启动安装CentOS。安装完系统心想这下应该完美解决了,直接就上npm i sharp ,事情到这又是一堆error,又遇到npm安装异常报错,记录如下。1、gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.1、gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.解决:npm config set python /path/to/executable/python2.7npm config set python /path/to/executable/python2.72、stack Error: EACCES: permission denied, mkdir2、stack Error: EACCES: permission denied, mkdir由于安装Linux使用的用户root账户,也遇到异常提示。为了避免这种情况,专门建一个用于运行 npm 的高权限用户;要么加 --unsafe-perm 参数,这样就不会切换到 nobody 。解决:npm i --unsafe-perm --allow-rootnpm i --unsafe-perm --allow-root3、前面讲过由于安装sharp需要编译C++ libvips,需要node-gyp3、前面讲过由于安装sharp需要编译C++ libvips,需要node-gyp解决:npm install --global node-gypnpm install --global node-gyp4、Error make:g++:not find4、Error make:g++:not findLinux安装后没有make需要安装解决:yum install -y make gcc-c++yum install -y make gcc-c++5、sudo npm install 提示 sudo: npm:找不到命令。5、sudo npm install 提示 sudo: npm:找不到命令。由于npm和node是解压安装没有安装到系统/use/bin下,所以通过软链解决解决:
ln -s /home/soft/node-v10.6.0/bin/npm /usr/bin/npm
ln -s /home/soft/node-v10.6.0/bin/np /usr/bin/node
ln -s /home/soft/node-v10.6.0/bin/npm /usr/bin/npmln -s /home/soft/node-v10.6.0/bin/np /usr/bin/node6、Mac 访问Parallels Desktop虚拟机Linux6、Mac 访问Parallels Desktop虚拟机Linux在虚拟机中使用ifconfig查询IP后回到Mac登录到Linuxssh root@10.211.x.xssh root@10.211.x.xroot@10.211.x.x同步文件
从本地复制到远程
# 拷贝文件
scp /home/test/test.txt root@192.168.0.2:/home/test/
# 拷贝目录
scp -r /home/test/ root@192.168.0.2:/home/test/
从远程复制到本地
# 拷贝文件
scp root@192.168.0.2:/home/test/ /home/test/test.txt
# 拷贝目录
scp -r root@192.168.0.2:/home/test/ v/home/test/
从本地复制到远程
# 拷贝文件
scp /home/test/test.txt root@192.168.0.2:/home/test/
# 拷贝目录
scp -r /home/test/ root@192.168.0.2:/home/test/
从远程复制到本地
# 拷贝文件
scp root@192.168.0.2:/home/test/ /home/test/test.txt
# 拷贝目录
scp -r root@192.168.0.2:/home/test/ v/home/test/root@192.168.0.2:/home/test/root@192.168.0.2:/home/test/root@192.168.0.2:/home/test/root@192.168.0.2:/home/test/以上就是sharp.js安装过程中遇到的问题总结的详细内容,关于sharp.js安装问题总结的资料请关注其它相关文章!