Skip to main content

在打包的代码中调用 bundle()

如果你收到以下错误:

🌐 If you receive the following error:

 ⨯ ./node_modules/@remotion/bundler/node_modules/webpack/lib/FileSystemInfo.js:9:0
Module not found: Can't resolve 'module'
Did you mean './module'?
Requests that should resolve in the current directory need to start with './'.

or

 ⨯ ./node_modules/@remotion/compositor-darwin-arm64/remotion
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

这意味着 bundle() 函数本身正在被打包,例如通过 Webpack 或 ESBuild。

🌐 it means that the bundle() function is being bundled itself for example by Webpack or ESBuild.

例如,如果在 Next.js 无服务器函数中调用 bundle()deploySite(),就会发生这种情况。

🌐 This occurs for example if bundle() or deploySite() is being called in a Next.js serverless function.

要打包 bundle() 函数,Webpack 需要特定的配置,但该配置缺失。

🌐 To bundle the bundle() function, Webpack needs specific configuration, which is missing.

然而,我们并不建议你在运行时调用 bundle()

🌐 However, we don't recommend that you call bundle() at runtime at all.

你真正想要的

🌐 What you actually want

很可能,你不想在运行时打包你的视频,而是在构建时打包。

🌐 Most likely, you don't want to bundle your video at runtime, but rather at build time.

只有在更改视频的源代码时,你才需要重新打包视频。然而,这在运行时通常是不必要的,因为你可以在不更改源代码的情况下对一切进行参数化。

🌐 You only need to re-bundle the video if you change the source code of it. However, this should not be necessary at runtime, as you can parametrize everything without changing the source code.

了解如何对内容使用输入属性进行参数化,以及对视频的元数据进行参数化。

🌐 See how to parametrize the content with input props as well as the metadata of your video.

秘诀

🌐 Recipes

如果你正在使用长时间运行的服务器: 我们建议在 Node.js 环境中调用一次 bundle(),然后在服务器的整个生命周期中重复使用它。请参见:在 Node.js 中渲染

如果你在 Lambda 上进行渲染:创建一个包并部署一次,可以使用 npx remotion sites create 或在非打包的 Node.js 脚本中使用 deploySite(),然后通过你获得的 URL 引用该包。

在两种情况下,使用 input props 对视频进行所有参数化。

🌐 In both cases, do all parameterization of the video using input props.

另请参阅

🌐 See also