Gatsby Build 在 Netlify 上因在本地工作而失败。 ffmpeg 依赖问题
Gatsby Build fails on Netlify by works locally. Ffmpeg dependency issue
我正在尝试在 Netlify 上部署我的站点,并且 gatsby build
命令在我的系统上运行得非常好。但是当我 运行 在 Netlify 上时,我 运行 遇到了如下所示的问题。
未处理的拒绝:找不到 ffprobe 似乎是问题所在。我认为这是因为我的系统 (macOS) 上安装了 ffmpeg,但在 Netlify 的构建过程中没有安装过程。有人可以指导我如何解决这个问题吗?
1:19:18 AM: info bootstrap finished - 5.299 s
1:19:18 AM: ⠀
1:19:22 AM: error UNHANDLED REJECTION Cannot find ffprobe
1:19:23 AM:
1:19:23 AM: Error: Cannot find ffprobe
1:19:23 AM:
1:19:23 AM: - ffprobe.js:145
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/ffprobe.js:145:31
1:19:23 AM:
1:19:23 AM: - capabilities.js:194
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:194:9
1:19:23 AM:
1:19:23 AM: - async.js:52
1:19:23 AM: [repo]/[async]/lib/async.js:52:16
1:19:23 AM:
1:19:23 AM: - async.js:1209
1:19:23 AM: [repo]/[async]/lib/async.js:1209:30
1:19:23 AM:
1:19:23 AM: - capabilities.js:186
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:186:13
1:19:23 AM:
1:19:23 AM: - capabilities.js:123
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:123:9
1:19:23 AM:
1:19:23 AM: - async.js:52
1:19:23 AM: [repo]/[async]/lib/async.js:52:16
1:19:23 AM:
1:19:23 AM: - async.js:1209
1:19:23 AM: [repo]/[async]/lib/async.js:1209:30
1:19:23 AM:
1:19:23 AM: - capabilities.js:116
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:116:11
1:19:23 AM:
1:19:23 AM: - utils.js:223
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/utils.js:223:16
1:19:23 AM:
1:19:23 AM: - which.js:68 F
1:19:23 AM: [repo]/[which]/which.js:68:16
1:19:23 AM:
1:19:23 AM: - which.js:80 E
1:19:23 AM: [repo]/[which]/which.js:80:29
1:19:23 AM:
1:19:23 AM: - which.js:89
1:19:23 AM: [repo]/[which]/which.js:89:16
1:19:23 AM:
1:19:23 AM: - index.js:42
1:19:23 AM: [repo]/[isexe]/index.js:42:5
1:19:23 AM:
1:19:23 AM: - mode.js:8
1:19:23 AM: [repo]/[isexe]/mode.js:8:5
1:19:23 AM:
1:19:23 AM:
1:19:23 AM: not finished run queries - 4.168s
1:19:23 AM: not finished Generating image thumbnails - 4.111s
1:19:23 AM: (sharp:1520): GLib-CRITICAL **: 16:19:23.397: g_hash_table_lookup: assertion 'hash_table != NULL' failed
1:19:23 AM: (sharp:1520): GLib-CRITICAL **: 16:19:23.438: g_hash_table_lookup: assertion 'hash_table != NULL' failed
1:19:23 AM: Skipping functions preparation step: no functions directory set
1:19:23 AM: Caching artifacts
1:19:23 AM: Started saving node modules
1:19:23 AM: Finished saving node modules
1:19:23 AM: Started saving pip cache
1:19:23 AM: Finished saving pip cache
1:19:23 AM: Started saving emacs cask dependencies
1:19:23 AM: Finished saving emacs cask dependencies
1:19:23 AM: Started saving maven dependencies
1:19:23 AM: Finished saving maven dependencies
1:19:23 AM: Started saving boot dependencies
1:19:23 AM: Finished saving boot dependencies
1:19:23 AM: Started saving go dependencies
1:19:23 AM: Finished saving go dependencies
1:19:27 AM: Error running command: Build script returned non-zero exit code: 1
1:19:27 AM: Failing build: Failed to build site
1:19:27 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
1:19:27 AM: Finished processing build request in 1m15.231125909s
我的gatsby-config.js
文件如下:
module.exports = {
siteMetadata: {
title: "#######",
author: "#######"
},
plugins: [
"gatsby-plugin-sass",
{
resolve: "gatsby-source-filesystem",
options: {
name: "images",
path: `${__dirname}/src/images`
}
},
"gatsby-transformer-sharp",
"gatsby-plugin-sharp",
"gatsby-transformer-ffmpeg",
"gatsby-plugin-ffmpeg"
]
}
Netlify 的构建映像 runs Ubuntu,因此您可以使用以下命令安装 ffmpeg
:
apt-get install ffmpeg
您可以将此脚本添加到您的 Netlify 构建命令中,即
apt-get install ffmpeg && npm run build
或将其作为新脚本粘贴到您的 package.json
。
关于在 Ubuntu 上构建最新版本 ffmpeg 的说明:https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
遗憾的是,您不能使用 apt-get install
向 Netlify 的构建映像添加额外的依赖项。 This help article 建议下载静态二进制文件以解决此限制。
fluent-ffmpeg
包(被gatsby-plugin-ffmpeg
使用)使用环境变量FFMPEG_PATH
和FFPROBE_PATH
来查找它所依赖的可执行文件。
我下载了 FFmpeg 的静态构建并将其添加到我的 gatsby 项目中。然后我能够为 FFMPEG_PATH
和 FFPROBE_PATH
变量使用正确的路径,并将它们添加到我的 Netlify 构建环境中。这解决了我的构建错误。
- FFmpeg 静态构建:https://www.johnvansickle.com/ffmpeg/
fluent-ffmpeg
环境变量:https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#ffmpeg-and-ffprobe
- 将环境变量添加到 Netlify 构建中:https://docs.netlify.com/configure-builds/environment-variables/
我正在尝试在 Netlify 上部署我的站点,并且 gatsby build
命令在我的系统上运行得非常好。但是当我 运行 在 Netlify 上时,我 运行 遇到了如下所示的问题。
未处理的拒绝:找不到 ffprobe 似乎是问题所在。我认为这是因为我的系统 (macOS) 上安装了 ffmpeg,但在 Netlify 的构建过程中没有安装过程。有人可以指导我如何解决这个问题吗?
1:19:18 AM: info bootstrap finished - 5.299 s
1:19:18 AM: ⠀
1:19:22 AM: error UNHANDLED REJECTION Cannot find ffprobe
1:19:23 AM:
1:19:23 AM: Error: Cannot find ffprobe
1:19:23 AM:
1:19:23 AM: - ffprobe.js:145
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/ffprobe.js:145:31
1:19:23 AM:
1:19:23 AM: - capabilities.js:194
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:194:9
1:19:23 AM:
1:19:23 AM: - async.js:52
1:19:23 AM: [repo]/[async]/lib/async.js:52:16
1:19:23 AM:
1:19:23 AM: - async.js:1209
1:19:23 AM: [repo]/[async]/lib/async.js:1209:30
1:19:23 AM:
1:19:23 AM: - capabilities.js:186
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:186:13
1:19:23 AM:
1:19:23 AM: - capabilities.js:123
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:123:9
1:19:23 AM:
1:19:23 AM: - async.js:52
1:19:23 AM: [repo]/[async]/lib/async.js:52:16
1:19:23 AM:
1:19:23 AM: - async.js:1209
1:19:23 AM: [repo]/[async]/lib/async.js:1209:30
1:19:23 AM:
1:19:23 AM: - capabilities.js:116
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/capabilities.js:116:11
1:19:23 AM:
1:19:23 AM: - utils.js:223
1:19:23 AM: [repo]/[fluent-ffmpeg]/lib/utils.js:223:16
1:19:23 AM:
1:19:23 AM: - which.js:68 F
1:19:23 AM: [repo]/[which]/which.js:68:16
1:19:23 AM:
1:19:23 AM: - which.js:80 E
1:19:23 AM: [repo]/[which]/which.js:80:29
1:19:23 AM:
1:19:23 AM: - which.js:89
1:19:23 AM: [repo]/[which]/which.js:89:16
1:19:23 AM:
1:19:23 AM: - index.js:42
1:19:23 AM: [repo]/[isexe]/index.js:42:5
1:19:23 AM:
1:19:23 AM: - mode.js:8
1:19:23 AM: [repo]/[isexe]/mode.js:8:5
1:19:23 AM:
1:19:23 AM:
1:19:23 AM: not finished run queries - 4.168s
1:19:23 AM: not finished Generating image thumbnails - 4.111s
1:19:23 AM: (sharp:1520): GLib-CRITICAL **: 16:19:23.397: g_hash_table_lookup: assertion 'hash_table != NULL' failed
1:19:23 AM: (sharp:1520): GLib-CRITICAL **: 16:19:23.438: g_hash_table_lookup: assertion 'hash_table != NULL' failed
1:19:23 AM: Skipping functions preparation step: no functions directory set
1:19:23 AM: Caching artifacts
1:19:23 AM: Started saving node modules
1:19:23 AM: Finished saving node modules
1:19:23 AM: Started saving pip cache
1:19:23 AM: Finished saving pip cache
1:19:23 AM: Started saving emacs cask dependencies
1:19:23 AM: Finished saving emacs cask dependencies
1:19:23 AM: Started saving maven dependencies
1:19:23 AM: Finished saving maven dependencies
1:19:23 AM: Started saving boot dependencies
1:19:23 AM: Finished saving boot dependencies
1:19:23 AM: Started saving go dependencies
1:19:23 AM: Finished saving go dependencies
1:19:27 AM: Error running command: Build script returned non-zero exit code: 1
1:19:27 AM: Failing build: Failed to build site
1:19:27 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
1:19:27 AM: Finished processing build request in 1m15.231125909s
我的gatsby-config.js
文件如下:
module.exports = {
siteMetadata: {
title: "#######",
author: "#######"
},
plugins: [
"gatsby-plugin-sass",
{
resolve: "gatsby-source-filesystem",
options: {
name: "images",
path: `${__dirname}/src/images`
}
},
"gatsby-transformer-sharp",
"gatsby-plugin-sharp",
"gatsby-transformer-ffmpeg",
"gatsby-plugin-ffmpeg"
]
}
Netlify 的构建映像 runs Ubuntu,因此您可以使用以下命令安装 ffmpeg
:
apt-get install ffmpeg
您可以将此脚本添加到您的 Netlify 构建命令中,即
apt-get install ffmpeg && npm run build
或将其作为新脚本粘贴到您的 package.json
。
关于在 Ubuntu 上构建最新版本 ffmpeg 的说明:https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
遗憾的是,您不能使用 apt-get install
向 Netlify 的构建映像添加额外的依赖项。 This help article 建议下载静态二进制文件以解决此限制。
fluent-ffmpeg
包(被gatsby-plugin-ffmpeg
使用)使用环境变量FFMPEG_PATH
和FFPROBE_PATH
来查找它所依赖的可执行文件。
我下载了 FFmpeg 的静态构建并将其添加到我的 gatsby 项目中。然后我能够为 FFMPEG_PATH
和 FFPROBE_PATH
变量使用正确的路径,并将它们添加到我的 Netlify 构建环境中。这解决了我的构建错误。
- FFmpeg 静态构建:https://www.johnvansickle.com/ffmpeg/
fluent-ffmpeg
环境变量:https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#ffmpeg-and-ffprobe- 将环境变量添加到 Netlify 构建中:https://docs.netlify.com/configure-builds/environment-variables/