在我安装 FontAwesome 之前部署工作正常。即使使用 FontAwesome,它在本地也能正常工作。但是安装了 FontAwesome 依赖项后,Cloudflare 失败了。
来自 Cloudflare Pages 的控制台日志:
23:32:59.378 Installing NPM modules using Yarn version 1.22.4
23:32:59.751 yarn install v1.22.4
23:32:59.851 [1/4] Resolving packages...
23:33:00.491 [2/4] Fetching packages...
23:33:00.802 error An unexpected error occurred: "https://npm.fontawesome.com/@fortawesome/free-solid-svg-icons/-/5.15.3/free-solid-svg-icons-5.15.3.tgz: Request failed \"401 Unauthorized\"".
23:33:00.802 info If you think this is a bug, please open a bug report with the information provided in "/opt/buildhome/repo/yarn-error.log".
23:33:00.802 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
23:33:23.195 Error during Yarn install
23:33:23.195 Failed: build command exited with code: 1
最佳答案
我刚刚在 DigitalOcean 上尝试构建 Strapi 应用程序时遇到了这个问题。我能够使用 this guide 修复它来自 FontAwesome 网站。
不幸的是,此解决方法需要有效的身份验证 token 。幸运的是,我已经是 FA Pro 订阅者。
在项目的根目录中创建一个 .npmrc 文件并添加以下代码,将“TOKEN”替换为您的身份验证 token 。登录 FA 网站后,可以在上面链接的指南中找到授权 token 。
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=TOKEN
我对 npm 身份验证不够精通,不知道为什么免费版本需要这个,但我确信对于 FA 的免费用户肯定有另一种解决方法。
关于npm - Cloudflare 页面部署 : Yarn install fails with 401 Unauthorized for fontawesome dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67766055/