Skip to content

🎥 Make videos programmatically with React

use a plugin for it

Jonny Burger57e65e28e2ef
diff --git a/packages/bundler/src/optional-dependencies.ts b/packages/bundler/src/optional-dependencies.ts
new file mode 100644
index 0000000000..37a0d9ce5a
--- /dev/null
+++ b/packages/bundler/src/optional-dependencies.ts
@@ -0,0 +1,27 @@
+// When Webpack cannot resolve these dependencies, it will not print an error message.
+
+import type {Compiler} from 'webpack';
+
+export const OPTIONAL_DEPENDENCIES = ['zod', '@remotion/zod-types'];
+
+export class AllowOptionalDependenciesPlugin {
+ filter(error: Error) {
+ for (const dependency of OPTIONAL_DEPENDENCIES) {
+ if (error.message.includes(`Can't resolve '${dependency}'`)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ apply(compiler: Compiler) {
+ compiler.hooks.afterEmit.tap(
+ 'AllowOptionalDependenciesPlugin',
+ (compilation) => {
+ compilation.errors = compilation.errors.filter(this.filter);
+ compilation.warnings = compilation.warnings.filter(this.filter);
+ }
+ );
+ }
+}
diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.ts
index 5b4117b029..9e68cb1257 100644
--- a/packages/bundler/src/webpack-config.ts
+++ b/packages/bundler/src/webpack-config.ts
@@ -9,6 +9,7 @@ import {getWebpackCacheName} from './webpack-cache';
import esbuild = require('esbuild');
import type {Configuration} from 'webpack';
+import {AllowOptionalDependenciesPlugin} from './optional-dependencies';
export type WebpackConfiguration = Configuration;
export type WebpackOverrideFn = (
@@ -118,6 +119,7 @@ export const webpackConfig = ({
[`process.env.${Internals.ENV_VARIABLES_ENV_NAME}`]:
JSON.stringify(envVariables),
}),
+ new AllowOptionalDependenciesPlugin(),
]
: [
new ProgressPlugin((p) => {
@@ -125,6 +127,7 @@ export const webpackConfig = ({
onProgress(Number((p * 100).toFixed(2)));
}
}),
+ new AllowOptionalDependenciesPlugin(),
],
output: {
hashFunction: 'xxhash64',