Skip to main content

staticFile() 不支持相对路径

如果您收到以下错误消息:

staticFile() 不支持相对路径。请传递位于 public/ 文件夹内的文件名。
staticFile() 不支持相对路径。请传递位于 public/ 文件夹内的文件名。

您可能尝试传递相对路径给 staticFile()

❌ 相对路径
tsx
import { staticFile } from "remotion";
staticFile("../public/image.png");
❌ 相对路径
tsx
import { staticFile } from "remotion";
staticFile("../public/image.png");
❌ 文件不应该有 ./ 前缀
tsx
import { staticFile } from "remotion";
staticFile("./image.png");
❌ 文件不应该有 ./ 前缀
tsx
import { staticFile } from "remotion";
staticFile("./image.png");

或者您可能尝试传递绝对路径:

❌ 文件不应该使用绝对路径
tsx
import { staticFile } from "remotion";
staticFile("/Users/bob/remotion-project/public/image.png");
❌ 文件不应该使用绝对路径
tsx
import { staticFile } from "remotion";
staticFile("/Users/bob/remotion-project/public/image.png");

或者您可能尝试添加一个不必要的 public/ 前缀:

❌ 文件不应该包含 public/ 前缀
tsx
import { staticFile } from "remotion";
staticFile("public/image.png");
❌ 文件不应该包含 public/ 前缀
tsx
import { staticFile } from "remotion";
staticFile("public/image.png");

相反,直接传递位于 public 文件夹内的文件名:

✅ 文件名
tsx
import { staticFile } from "remotion";
staticFile("image.png");
✅ 文件名
tsx
import { staticFile } from "remotion";
staticFile("image.png");

另请参阅