parcel-bundler/parcel · error · ThrowableDiagnostic

Vue config should be an object.

Error message

Vue config should be an object.

What it means

Thrown by @parcel/transformer-vue when a discovered vue.config.{js,cjs,mjs} file exports a value whose typeof is not 'object'. The transformer expects a plain configuration object (customBlocks, compilerOptions); any other shape (string, number, array, function without return) is rejected before reading keys.

Source

Thrown at packages/transformers/vue/src/VueTransformer.js:45

      [
        '.vuerc',
        '.vuerc.json',
        '.vuerc.js',
        '.vuerc.cjs',
        '.vuerc.mjs',
        'vue.config.js',
        'vue.config.cjs',
        'vue.config.mjs',
      ],
      {packageKey: 'vue'},
    );
    let contents = {};
    if (conf) {
      config.invalidateOnStartup();
      contents = conf.contents;
      if (typeof contents !== 'object') {
        // TODO: codeframe
        throw new ThrowableDiagnostic({
          diagnostic: {
            message: 'Vue config should be an object.',
            origin: '@parcel/transformer-vue',
          },
        });
      }
    }
    return {
      customBlocks: contents.customBlocks || {},
      filePath: conf && conf.filePath,
      compilerOptions: contents.compilerOptions || {},
    };
  },
  canReuseAST({ast}) {
    return ast.type === 'vue' && semver.satisfies(ast.version, '^3.0.0');
  },
  async parse({asset, options}) {
    // TODO: This parses the vue component multiple times. Fix?

View on GitHub (pinned to 59484858a1)

Solutions

  1. Ensure vue.config.js exports a plain object: `module.exports = { compilerOptions: {...} }`.
  2. If using ESM, write `export default { compilerOptions: {} };`.
  3. Remove the vue.config file if no custom compiler options are needed.
  4. Verify the file is not accidentally exporting the result of a function call that returns a non-object.

Example fix

// before: module.exports = 'production';
// after:  module.exports = { compilerOptions: { whitespace: 'condense' } };
Defensive patterns

Strategy: type-guard

Validate before calling

import conf from './vue.config';
if (conf !== null && typeof conf !== 'object' || Array.isArray(conf)) {
  throw new Error('vue.config must export a plain object');
}

Type guard

function isVueConfig(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Prevention

When it happens

Trigger: Parcel resolves a vue config file via the packageKey 'vue' or one of the well-known filenames, then checks typeof conf.contents. A module-default-exported string, a named export misread, or `export default []` triggers it.

Common situations: Author writes `module.exports = 'something'` instead of an object, uses `export default function()` (function, not object), or the config file is actually a CommonJS file loaded in a way that yields module.exports = string. Also happens when a build tool rewrites the export into a non-object.

Related errors


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