我在一个serverless-framework项目中同时使用sharp包和serverless-bundle。使用这个custom.bundle.packagerOptions.scripts脚本:rm -rf node_modules/sharp && npm install --arch=x64 --platform=linux --target=10.15.0 sharp,我可以很好地运行和部署代码。
当我尝试对触及sharp包的代码运行测试时,我得到以下错误:'linux-x64' binaries cannot be used on the 'darwin-x64' platform. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.
我不打算测试sharp的实现,而是模拟导入它的JavaScript文件。下面是我遇到这个问题的测试文件:https://github.com/groffcole/art-center-service/blob/master/ports/GalleriesHttpPort.test.js
我做错了什么?
谢谢。
发布于 2020-02-17 04:44:45
我只是偶然解决了这个问题。我删除了整个node_modules目录并运行了npm install。我相信,因为我使用的是serverless-bundle包,所以出现了问题。现在,我可以使用serverless-bundle test命令成功运行测试。
以下是我在serverless.yml文件中的自定义serverless-bundle设置,以供参考:
custom:
bundle:
caching: false
packagerOptions:
scripts:
- rm -rf node_modules/sharp && npm install --arch=x64 --platform=linux --target=10.15.0 sharphttps://stackoverflow.com/questions/60244846
复制相似问题