parcel-bundler/parcel · error · Error
Could not resolve module "${id}" from "${from}"
Error message
Could not resolve module "${id}" from "${from}" What it means
Thrown by ReactStaticPackager.loadModule during React Server Components / static (SSG) rendering. Parcel evaluates bundle code in a VM context at build time and resolves every specifier through @parcel/node-resolver-core (a server resolver for 'react-server' env, a client resolver otherwise). When resolver.resolve returns an error object (not an exception) for the given id/parent pair, the packager converts it into this thrown Error. It means Node-style module resolution failed inside the SSR/SSG sandbox.
Source
Thrown at packages/packagers/react-static/src/ReactStaticPackager.js:571
} else {
throw new Error('Bundle not found');
}
};
// No-op. We can access the bundle graph directly.
parcelRequire.extendImportMap = () => {};
// Resolve and load a module by specifier.
let loadModule = (id: string, from: string, env = 'react-client') => {
let resolver = env === 'react-server' ? serverResolver : clientResolver;
let res = resolver.resolve({
filename: id,
specifierType: 'commonjs',
parent: from,
});
if (res.error) {
throw new Error(`Could not resolve module "${id}" from "${from}"`);
}
let defaultRequire = Module.createRequire(from);
let resolution = res.resolution;
if (resolution.type === 'Builtin') {
let {scheme, module} = resolution.value;
return defaultRequire(scheme ? `${scheme}:${module}` : module);
}
if (resolution.type === 'Path') {
let cacheKey = resolution.value + '#' + env;
const cachedModule = moduleCache.get(cacheKey);
if (cachedModule) {
return cachedModule.exports;
}
let assetId = assetsByFilePath.get(cacheKey);
if (assetId) {View on GitHub (pinned to 59484858a1)
Solutions
- Run the build with PARCEL_LOG_LEVEL=verbose (or --log-level verbose) and check the prior resolver diagnostics to see which specifier and parent file are involved.
- Confirm the named package is resolvable from the `from` path: run `node -e "console.log(require.resolve('${id}', {paths:['${from}']}))"` from the project root.
- If the package is missing, install it as a real dependency (`npm i <pkg>`); do not rely on a transitive dep that can be hoisted away.
- If the package exists but is excluded by `exports`, add the matching condition to your target env or add an explicit `react-server`/`import` export in the dependency's package.json.
- For relative specifiers, verify the file extension (Parcel matches the literal specifier) and that the path is correct relative to `from`.
- For monorepos, ensure the package is resolvable from the specific workspace that owns the failing source file; check hoisting in pnpm (use public-hoist-pattern or node-linker if needed).
Example fix
// before (in a react-server module)
import {render} from 'some-node-lib';
// resolver fails because 'some-node-lib' has no react-server-compatible export
// after: add the export condition or alias, OR ensure the package is installed
// package.json of some-node-lib
"exports": {
".": {
"react-server": "./index.server.js",
"default": "./index.js"
}
} Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight resolve check before running an RSC/SSG build
const {create} = require('@parcel/node-resolver-core');
async function assertResolvable(specifier, fromPath, env = 'react-server') {
const resolver = create({fs: require('fs'), projectRoot: process.cwd()});
const res = await resolver.resolve({
filename: specifier,
specifierType: 'commonjs',
parent: fromPath,
});
if (res.error) {
throw new Error(`Pre-build check failed: ${specifier} from ${fromPath} (${res.error})`);
}
return res.resolution;
} Try / catch
// Wrap your build entrypoint
try {
await runRSCBuild();
} catch (err) {
if (/Could not resolve module/.test(err.message)) {
const m = err.message.match(/"([^"]+)" from "([^"]+)"/);
console.error(`[build] missing dependency: ${m?.[1]} (from ${m?.[2]})`);
process.exitCode = 2;
} else {
throw err;
}
} Prevention
- Keep a single source of truth for dependencies in package.json and run `npm ls` in CI to catch missing packages.
- Pin projectRoot explicitly via CLI --dist-dir/--config so resolver parent paths are deterministic.
- For monorepos, validate that every package imported by RSC entry points is resolvable from the workspace that owns the entry.
When it happens
Trigger: A bundle evaluated by the react-static packager requires/import a specifier that the configured NodeResolver cannot resolve. Calls into loadModule happen transitively via the `require` shim that runModule injects, so any require() executed during RSC rendering of a module walks here. resolution.error is set when the file is missing, the package is not installed, or an `exports`/`browser` map excludes it for the given env.
Common situations: Importing a Node-only or browser-only package from a 'react-server' module that the serverResolver cannot map; missing dependency in node_modules after an incomplete install; typo'd relative specifier in code only reachable during SSG/RSC evaluation; a package whose package.json `exports` field restricts the requested condition (e.g. no `react-server` export); symlinks/monorepo hoisting causing the resolver to look in the wrong node_modules.
Related errors
- Could not find module "${name}", but it was listed in packag
- Scope hoisting is not supported with SSG
- Unsupported output format: ${b.env.outputFormat}
- use server-entry must be imported in a server environment
- failed to locate file ${originalPath}
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/29e6874b616cd373.
Report an issue: GitHub.