parcel-bundler/parcel · error · Error
Unsupported main field "${field}"
Error message
Unsupported main field "${field}" What it means
Thrown by @parcel/node-resolver-core's mainFieldsToEntries helper when a mainFields config entry is anything other than 'main', 'module', 'source', 'browser', or 'types'. The switch maps each known field to a bitmask flag; the default branch rejects unknown fields with a plain Error (no diagnostic wrapping).
Source
Thrown at packages/utils/node-resolver-core/src/Wrapper.js:845
for (let field of mainFields) {
switch (field) {
case 'main':
entries |= MAIN;
break;
case 'module':
entries |= MODULE;
break;
case 'source':
entries |= SOURCE;
break;
case 'browser':
entries |= BROWSER;
break;
case 'types':
entries |= TYPES;
break;
default:
throw new Error(`Unsupported main field "${field}"`);
}
}
return entries;
}
View on GitHub (pinned to 59484858a1)
Solutions
- Restrict mainFields to the supported set: main, module, source, browser, types.
- Remove any custom/typo entry from the mainFields array in your resolver config.
- If you need a custom package.json field, handle it via a different resolver hook rather than mainFields.
Example fix
// before mainFields: ['browser', 'module', 'main', 'esnext'] // after mainFields: ['browser', 'module', 'main']
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = new Set(['main','module','source','browser','types']);
const bad = (mainFields || []).filter(f => !ALLOWED.has(f));
if (bad.length) throw new Error('Unsupported mainFields: ' + bad.join(', ')); Type guard
const ALLOWED_MAIN_FIELDS = new Set(['main','module','source','browser','types']);
function areValidMainFields(fields) {
return fields.every(f => ALLOWED_MAIN_FIELDS.has(f));
} Prevention
- Limit mainFields to the supported set when porting config from other bundlers.
- Do not list custom package.json fields in mainFields.
- Add a CI schema check on resolver config.
When it happens
Trigger: User-configured mainFields (resolver option) contains a typo or unsupported value such as 'main.js', 'esnext', 'browser2', 'umd'.
Common situations: Copying a webpack/resolve.mainFields list into Parcel's resolver config, custom fields in package.json mistakenly listed, or a typo when migrating from another bundler.
Related errors
- Targets option is an empty array
- Could not find target with name "${target}"
- Missing distDir for target "${name}"
- Failed to parse package.json
- PostCSS config must have plugins
AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13).
Data as JSON: /api/errors/db65309641f6a6c8.
Report an issue: GitHub.