{"record":{"id":"41e24718c5a57995","repo":"remotion-dev/remotion","slug":"installpackages-is-only-available-in-the-studio","errorCode":null,"errorMessage":"installPackages() is only available in the Studio","messagePattern":"installPackages\\(\\) is only available in the Studio","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio/src/api/install-package.ts","lineNumber":14,"sourceCode":"import type {\n\tInstallPackageResponse,\n\tPackageInstallSpec,\n} from '@remotion/studio-shared';\nimport {getRemotionEnvironment} from 'remotion';\nimport {callApi} from '../components/call-api';\nimport {getBrowserStudioOperations} from '../helpers/browser-studio-operations';\nimport {withRequiredAuxiliaryPackages} from '../helpers/optional-package-dependencies';\n\nexport const installPackages = async (\n\tdependencies: readonly PackageInstallSpec[],\n): Promise<InstallPackageResponse> => {\n\tif (!getRemotionEnvironment().isStudio) {\n\t\tthrow new Error('installPackages() is only available in the Studio');\n\t}\n\n\tconst dependenciesWithAuxiliaryPackages =\n\t\twithRequiredAuxiliaryPackages(dependencies);\n\n\tconst browserStudioOperations = getBrowserStudioOperations();\n\tif (browserStudioOperations !== null) {\n\t\tconst response =\n\t\t\tawait browserStudioOperations.packageInstallation.installPackages({\n\t\t\t\tdependencies: dependenciesWithAuxiliaryPackages,\n\t\t\t});\n\t\tif (!response.success) {\n\t\t\tconst error = new Error(response.reason);\n\t\t\terror.stack = response.stack;\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn {};","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/remotion-dev/remotion/blob/b2f4e34732f3c6c222ea029413e22dc402218cd7/packages/studio/src/api/install-package.ts#L1-L32","documentation":"installPackages() from @remotion/studio installs npm packages by calling the Studio server's /api/install-package endpoint (or the Browser Studio operations bridge). It is a Studio-only API: when getRemotionEnvironment().isStudio is false - the code runs inside a regular render, the @remotion/player, or any plain React/Node app - it throws before doing anything.","triggerScenarios":"Importing installPackages from '@remotion/studio' inside a composition, a hook that also executes during rendering, or a Node script; calling it from a preview embedded outside Studio.","commonSituations":"Sharing a utility module between Studio toolbar components and video compositions; copying Studio example code into a Player app; SSR builds that execute the module outside the Studio environment.","solutions":["Only call installPackages() from Studio-only surfaces (custom Studio UI registered for the Studio, not compositions that also render).","Guard the call with getRemotionEnvironment().isStudio before invoking it.","For programmatic package installation outside Studio, spawn your package manager (bun/npm/pnpm) directly instead of using this API.","Audit import paths - pulling @remotion/studio into render-time code also bloats the render bundle."],"exampleFix":"// before\nimport {installPackages} from '@remotion/studio';\n\nexport const install = () => installPackages([{name: 'lodash'}]); // throws outside Studio\n\n// after\nimport {getRemotionEnvironment} from 'remotion';\nimport {installPackages} from '@remotion/studio';\n\nexport const install = () => {\n  if (!getRemotionEnvironment().isStudio) {\n    throw new Error('Package installation is only available inside Remotion Studio');\n  }\n  return installPackages([{name: 'lodash'}]);\n};","handlingStrategy":"type-guard","validationCode":"import {getRemotionEnvironment} from 'remotion';\n\nif (!getRemotionEnvironment().isStudio) {\n  // do not call installPackages() here - it throws outside Studio\n} else {\n  await installPackages([{name: 'lodash'}]);\n}","typeGuard":"import {getRemotionEnvironment} from 'remotion';\n\nexport const canInstallPackages = (): boolean =>\n  getRemotionEnvironment().isStudio;","tryCatchPattern":"try {\n  await installPackages(deps);\n} catch (err) {\n  if (err.message.includes('only available in the Studio')) {\n    // called outside Studio - skip or route to a package manager directly\n  } else {\n    throw err;\n  }\n}","preventionTips":["Keep Studio-only calls (installPackages, restartStudio) out of compositions and any module that render-time code imports.","Gate every Studio API call behind getRemotionEnvironment().isStudio.","For installs outside Studio, spawn your package manager directly instead of using the Studio API."],"tags":["studio","api-misuse","environment-check","package-installation"],"backgroundTag":"studio-only-api","analyzedSha":"b2f4e34732f3c6c222ea029413e22dc402218cd7","analyzedAt":"2026-09-09T13:27:51.281Z","contentChangedAt":"2026-09-09T13:27:51.281Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}