我正在部署具有外部依赖的 CF 页面功能
我使用
npm install jspdf
在本地安装了它,然后我的页面可以在本地运行。它还生成了 package.json 和 package-lock.json。我提交并推送到我的存储库,但随后我的构建失败并显示以下日志:
3:08:10.954 Cloning repository...
23:08:12.065 From https://github.com/charelF/wg-form-page
23:08:12.065 * branch bf14b72070afb75b1b8c4a5e13d5caa3b7aea792 -> FETCH_HEAD
23:08:12.066
23:08:12.110 HEAD is now at bf14b72 nice
23:08:12.111
23:08:12.219
23:08:12.252 Success: Finished cloning repository files
23:08:12.979 No build command specified. Skipping build step.
23:08:12.980 Found Functions directory at /functions. Uploading.
23:08:14.565 ✘ [ERROR] 1 error(s) and 0 warning(s) when compiling Worker.
23:08:14.566
23:08:14.566
23:08:14.569
23:08:14.570 ✘ [ERROR] Could not resolve "jspdf"
23:08:14.571
23:08:14.571 pdfmaker.js:1:22:
23:08:14.571 1 │ import { jsPDF } from 'jspdf'
23:08:14.571 ╵ ~~~~~~~
23:08:14.571
23:08:14.571 You can mark the path "jspdf" as external to exclude it from the bundle, which will remove this error.
23:08:14.572
23:08:14.572
23:08:14.575 ✘ [ERROR] Build failed with 1 error:
23:08:14.575
23:08:14.575 pdfmaker.js:1:22: ERROR: Could not resolve "jspdf"
23:08:14.575
23:08:14.575
23:08:14.585 Failed building Pages Functions.
23:08:15.476 Failed: an internal error occurred. If this continues, contact support: https://cfl.re/3WgEyrH
由于我没有使用框架,所以我将构建命令留空。但是,然后什么也没有构建,这就是上面的日志显示错误的原因。解决方案是在构建命令中包含任何内容。就我而言,我将:
echo "Hello World!"
放入 buidl 命令中,然后部署就成功了。
最初在discord上询问:https://discord.com/channels/595317990191398933/910978223968518144/1155069343365865534
因为这个问题打开了 github 问题:https://github.com/cloudflare/cloudflare-docs/issues/10841