Deno 支援
在 Deno 執行環境中使用 Remotion 的說明、相容性限制與替代方案。
Deno 支援
Deno 是由 Node.js 創始人 Ryan Dahl 開發的現代 JavaScript/TypeScript 執行環境,內建 TypeScript 支援、更嚴格的安全模型,以及與瀏覽器 API 相容的設計。
目前的支援狀況
Remotion 目前不正式支援 Deno。
Remotion 的核心依賴 Node.js 的特定 API(如 child_process、fs、path 等),雖然 Deno 提供了部分 Node.js 相容層(node: 協議),但 Remotion 使用的原生模組(.node 檔案)在 Deno 中無法直接執行。
為什麼 Deno 目前不相容?
- 原生模組:Remotion 渲染器使用了以 C++ 撰寫的原生 Node.js 模組,Deno 的相容層目前不支援這些模組。
- webpack 依賴:Remotion 的打包流程深度依賴 webpack 和 Node.js 生態系。
- Chromium 整合:Remotion 啟動 Chromium 的方式與 Node.js 的
child_process緊密耦合。 - npm 套件格式:雖然 Deno 支援 npm 套件,但 Remotion 使用的部分功能仍有相容性問題。
使用 Deno 的替代方案
若你的專案使用 Deno,以下是幾種可行的替代方案:
方案一:微服務架構
將 Remotion 渲染功能拆分為獨立的 Node.js 微服務,透過 HTTP API 與 Deno 主服務溝通:
// render-service/server.ts (Node.js)
import express from "express";
import { renderMedia, selectComposition } from "@remotion/renderer";
import { bundle } from "@remotion/bundler";
const app = express();
app.use(express.json());
app.post("/render", async (req, res) => {
const { compositionId, inputProps } = req.body;
// ... 渲染邏輯
res.json({ outputPath });
});
app.listen(3001);// main.ts (Deno)
// 向 Node.js 渲染服務發出請求
const response = await fetch("http://localhost:3001/render", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
compositionId: "MyComp",
inputProps: { title: "Hello" },
}),
});
const { outputPath } = await response.json();
console.log("影片已渲染至:", outputPath);方案二:使用 Remotion Lambda
透過 AWS Lambda 執行渲染,Deno 只負責觸發渲染任務:
// Deno 觸發 Lambda 渲染
const response = await fetch("https://your-api.example.com/render", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${Deno.env.get("API_KEY")}`,
},
body: JSON.stringify({ inputProps: { title: "Hello from Deno" } }),
});方案三:CLI 子程序
在 Deno 中呼叫 Node.js 的 Remotion CLI:
// Deno 呼叫 Node.js 執行 Remotion
const command = new Deno.Command("npx", {
args: ["remotion", "render", "MyComp", "out/video.mp4"],
env: {
...Deno.env.toObject(),
REMOTION_INPUT_PROPS: JSON.stringify({ title: "Hello" }),
},
});
const { success, stderr } = await command.output();
if (!success) {
console.error("渲染失敗:", new TextDecoder().decode(stderr));
} else {
console.log("渲染完成");
}Deno 的 Node.js 相容層
Deno 持續改善對 Node.js API 的相容性。若你想嘗試在 Deno 中使用 Remotion,可以使用 --compat 旗標:
# 嘗試以 Node.js 相容模式執行(不保證可行)
deno run --compat --allow-all render.ts但目前這仍有許多限制,不建議在生產環境使用。
未來展望
隨著 Deno 對 Node.js 相容性的持續改善,未來可能會有更好的整合方式。建議追蹤:
- Deno 的 Node.js 相容性文件
- Remotion GitHub 上關於 Deno 支援的 討論與 Issue
小結
- Remotion 目前不正式支援 Deno。
- 核心原因是原生模組、webpack 整合與 Node.js API 的深度依賴。
- 建議使用微服務架構,將渲染任務交給 Node.js 服務,Deno 負責其餘業務邏輯。
- 也可以考慮使用 Remotion Lambda,讓 Deno 只負責觸發渲染任務。