Skip to content

🎥 Make videos programmatically with React

warn if passing an entry point that does not call registerRoot.

Jonny Burger67bc6fc91a1d
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.ts
index 096d324ffc..65f76fdf6a 100644
--- a/packages/bundler/src/bundle.ts
+++ b/packages/bundler/src/bundle.ts
@@ -1,4 +1,4 @@
-import fs from 'fs';
+import fs, {promises} from 'fs';
import os from 'os';
import path from 'path';
import {promisify} from 'util';
@@ -84,6 +84,7 @@ export const getConfig = ({
export type BundleOptions = {
entryPoint: string;
onProgress?: (progress: number) => void;
+ ignoreRegisterRootWarning?: boolean;
} & LegacyBundleOptions;
type Arguments =
@@ -132,6 +133,20 @@ const findClosestPackageJsonFolder = (currentDir: string): string | null => {
return null;
};
+const validateEntryPoint = async (entryPoint: string) => {
+ const contents = await promises.readFile(entryPoint, 'utf8');
+ if (!contents.includes('registerRoot')) {
+ throw new Error(
+ [
+ `You passed ${entryPoint} as your entry point, but this file does not contain "registerRoot".`,
+ 'You should use the file that calls registerRoot() as the entry point.',
+ 'To ignore this error, pass "ignoreRegisterRootWarning" to bundle().',
+ 'This error cannot be ignored on the CLI.',
+ ].join(' ')
+ );
+ }
+};
+
export async function bundle(...args: Arguments): Promise<string> {
const actualArgs = convertArgumentsIntoOptions(args);
const entryPoint = path.resolve(process.cwd(), actualArgs.entryPoint);
@@ -140,6 +155,10 @@ export async function bundle(...args: Arguments): Promise<string> {
findClosestPackageJsonFolder(entryPoint) ??
process.cwd();
+ if (!actualArgs.ignoreRegisterRootWarning) {
+ await validateEntryPoint(entryPoint);
+ }
+
const outDir = await prepareOutDir(actualArgs?.outDir ?? null);
// The config might use an override which might use
diff --git a/packages/docs/docs/bundle.md b/packages/docs/docs/bundle.md
index af8c8f7f75..3ed2231c6d 100644
--- a/packages/docs/docs/bundle.md
+++ b/packages/docs/docs/bundle.md
@@ -101,6 +101,10 @@ Reports progress of how many bytes have been written while copying the `public/`
Gets called when a symbolic link is detected in the `public/` directory. Since Remotion will forward the symbolic link, it might be useful to display a hint to the user that if the original symbolic link gets deleted, the bundle will also break.
+#### `ignoreRegisterRootWarning?` <AvailableFrom v="3.3.46" />
+
+Ignore an error that gets thrown if you pass an entry point file which does not contain `registerRoot`.
+
## Legacy function signature
Remotion versions earlier than v3.2.17 had the following function signature instead: