Skip to content

πŸŽ₯ Make videos programmatically with React

runtime check for remote URLs

Jonny Burger602dd4619eed
diff --git a/packages/cli/src/preview-server/error-overlay/remotion-overlay/get-help-link.ts b/packages/cli/src/preview-server/error-overlay/remotion-overlay/get-help-link.ts
index 4507b32079..bbebaf8290 100644
--- a/packages/cli/src/preview-server/error-overlay/remotion-overlay/get-help-link.ts
+++ b/packages/cli/src/preview-server/error-overlay/remotion-overlay/get-help-link.ts
@@ -29,5 +29,12 @@ export const getHelpLink = (message: string): THelpLink | null => {
};
}
+ if (message.includes('https://remotion.dev/docs/staticfile-remote-urls')) {
+ return {
+ title: 'staticFile() remote URLs',
+ url: 'https://remotion.dev/docs/staticfile-remote-urls',
+ };
+ }
+
return null;
};
diff --git a/packages/core/src/static-file.ts b/packages/core/src/static-file.ts
index d5ba0568a7..8e4980dfa5 100644
--- a/packages/core/src/static-file.ts
+++ b/packages/core/src/static-file.ts
@@ -15,6 +15,12 @@ const inner = (path: string): string => {
};
export const staticFile = (path: string) => {
+ if (path.startsWith('http://') || path.startsWith('https://')) {
+ throw new TypeError(
+ `staticFile() does not support remote URLs - got "${path}". Instead, pass the URL without wrapping it in staticFile(). See: https://remotion.dev/docs/staticfile-remote-urls`
+ );
+ }
+
if (path.startsWith('..') || path.startsWith('./')) {
throw new TypeError(
`staticFile() does not support relative paths - got "${path}". Instead, pass the name of a file that is inside the public/ folder. See: https://remotion.dev/docs/staticfile-relative-paths`
diff --git a/packages/docs/docs/static-file-remote-urls.md b/packages/docs/docs/static-file-remote-urls.md
new file mode 100644
index 0000000000..75846e5df9
--- /dev/null
+++ b/packages/docs/docs/static-file-remote-urls.md
@@ -0,0 +1,35 @@
+---
+id: staticfile-remote-urls
+title: staticFile() does not support remote URLs
+sidebar_label: staticFile() remote URLs
+---
+
+If you got the following error message:
+
+```
+staticFile() does not support remote URLs. Instead, pass the URL without wrapping it in staticFile().
+```
+
+You have tried to pass a remote URL to `staticFile()`. You don't need to wrap the path in `staticFile`, you can pass it directly:
+
+```tsx twoslash title="❌ Remote URL inside staticFile()"
+import { Img, staticFile } from "remotion";
+
+const MyComp = () => {
+ return <Img src={staticFile("https://example.com/image.png")} />;
+};
+```
+
+Instead, :
+
+```tsx twoslash title="βœ… Remote URL passed directly"
+import { Img } from "remotion";
+
+const MyComp = () => {
+ return <Img src={"https://example.com/image.png"} />;
+};
+```
+
+## See also
+
+- [`staticFile()`](/docs/staticfile)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 11bc639d91..c05fcbe90e 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -273,6 +273,7 @@ module.exports = {
"slow-method-to-extract-frame",
"wrong-composition-mount",
"staticfile-relative-paths",
+ "staticfile-remote-urls",
],
},
{