Skip to content

🎥 Make videos programmatically with React

`@remotion/bundler`: filter out webpack warnings of optional dependencies

Jonny Burger5c676f8f19e3
diff --git a/packages/bundler/src/hide-expression-dependency.ts b/packages/bundler/src/hide-expression-dependency.ts
new file mode 100644
index 0000000000..26c9ce26e1
--- /dev/null
+++ b/packages/bundler/src/hide-expression-dependency.ts
@@ -0,0 +1,31 @@
+// When Webpack cannot resolve these dependencies, it will not print an error message.
+
+import type {Compiler} from 'webpack';
+
+// If importing TypeScript, it will give this warning:
+// WARNING in ./node_modules/typescript/lib/typescript.js 6304:33-52
+// Critical dependency: the request of a dependency is an expression
+export class AllowDependencyExpressionPlugin {
+ filter(error: Error) {
+ if (
+ error.message.includes('the request of a dependency is an expression')
+ ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ apply(compiler: Compiler) {
+ compiler.hooks.afterCompile.tap('Com', (compilation) => {
+ compilation.errors = compilation.errors.filter(this.filter);
+ });
+ 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 72d0c5520f..0ad90d1667 100644
--- a/packages/bundler/src/webpack-config.ts
+++ b/packages/bundler/src/webpack-config.ts
@@ -10,6 +10,7 @@ import esbuild = require('esbuild');
import {NoReactInternals} from 'remotion/no-react';
import type {Configuration} from 'webpack';
import {CaseSensitivePathsPlugin} from './case-sensitive-paths';
+import {AllowDependencyExpressionPlugin} from './hide-expression-dependency';
import {AllowOptionalDependenciesPlugin} from './optional-dependencies';
export type WebpackConfiguration = Configuration;
@@ -124,6 +125,7 @@ export const webpackConfig = async ({
new webpack.HotModuleReplacementPlugin(),
define,
new AllowOptionalDependenciesPlugin(),
+ new AllowDependencyExpressionPlugin(),
]
: [
new ProgressPlugin((p) => {
@@ -136,6 +138,7 @@ export const webpackConfig = async ({
}),
define,
new AllowOptionalDependenciesPlugin(),
+ new AllowDependencyExpressionPlugin(),
],
output: {
hashFunction: 'xxhash64',