parcel-bundler/parcel · error · Error
Cannot require '${resolved}' in the browser
Error message
Cannot require '${resolved}' in the browser What it means
Thrown by `BrowserPackageManager.require` in the in-browser Parcel REPL when a resolved module is not in the `BUILTINS` map. The REPL only has the parcel core plugins bundled in; any other package can be resolved by path but cannot actually be `require()`-loaded in the browser sandbox.
Source
Thrown at packages/dev/repl/src/parcel/BrowserPackageManager.js:161
}
async require(
name: DependencySpecifier,
from: FilePath,
opts: ?{|
range?: ?SemverRange,
shouldAutoInstall?: boolean,
saveDev?: boolean,
|},
): Promise<any> {
let {resolved} = await this.resolve(name, from, opts);
// $FlowFixMe
if (resolved in BUILTINS) {
return BUILTINS[resolved];
}
throw new Error(`Cannot require '${resolved}' in the browser`);
}
async resolve(
name: DependencySpecifier,
from: FilePath,
// eslint-disable-next-line no-unused-vars
options?: ?{|
range?: ?SemverRange,
shouldAutoInstall?: boolean,
saveDev?: boolean,
|},
): Promise<ResolveResult> {
if (name.startsWith('@parcel/') && name !== '@parcel/watcher') {
return Promise.resolve({
resolved: name,
pkg: {
name: name,
version: '2.0.0',View on GitHub (pinned to 59484858a1)
Solutions
- Only reference parcel plugins that ship in the REPL's BUILTINS list (the standard `@parcel/*` set).
- Remove custom `.parcelrc` entries that pull in third-party plugins when running in the REPL.
- If you control the REPL build, add the needed package to the BUILTINS map at build time.
- Run the build with a local Parcel install instead of the in-browser REPL for non-builtin plugins.
Example fix
// before — .parcelrc references a non-bundled plugin
{
"transformers": { "*.foo": "parcel-transformer-foo" }
}
// after — drop it in the REPL
{ "extends": "@parcel/config-default" } Defensive patterns
Strategy: validation
Validate before calling
import { BUILTINS } from '@parcel/repl/.../BrowserPackageManager.js';
function canRequireInRepl(resolved) { return resolved in BUILTINS; } Type guard
function isBuiltinPlugin(spec) {
return typeof spec === 'string' && Object.prototype.hasOwnProperty.call(BUILTINS, spec);
} Prevention
- Constrain REPL projects to the default parcel config.
- Avoid third-party parcel plugins in REPL projects.
- Extend BUILTINS at build time if a custom plugin is required.
When it happens
Trigger: A parcel plugin/config tries to `require()` a package that is not one of the pre-bundled `@parcel/*` plugins; resolving succeeds to a path but the package isn't in `BUILTINS`.
Common situations: REPL loads a project whose parcel config references a custom/third-party plugin or runtime not bundled into the REPL; a transformer tries to require a helper package at runtime.
Related errors
- IDBCache is only supported in the browser
- More than one target is not supported in serve mode
- NodeFS isn't available in the browser
- No dynamic require possible: ${workerPath}
- No dynamic require possible: ${location}
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/db1a172ed8bf54d4.
Report an issue: GitHub.