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

  1. Restrict mainFields to the supported set: main, module, source, browser, types.
  2. Remove any custom/typo entry from the mainFields array in your resolver config.
  3. 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

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


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/db65309641f6a6c8. Report an issue: GitHub.