vuejs/vue-cli · error · Error

Invalid type for option 'vuePlugins.service', expected 'arra

Error message

Invalid type for option 'vuePlugins.service', expected 'array' but got ${typeof files}.

What it means

Service.loadUserOptions reads local plugins from the `vuePlugins.service` field in package.json and maps each entry to a module file. It must be an array of path strings; any other type cannot be iterated with `.map`, so it is rejected with the actual typeof received.

Source

Thrown at packages/@vue/cli-service/lib/Service.js:222

            if (!apply) {
              warn(`Optional dependency ${id} is not installed.`)
              apply = () => {}
            }

            return { id, apply }
          } else {
            return idToPlugin(id, resolveModule(id, this.pkgContext))
          }
        })

      plugins = builtInPlugins.concat(projectPlugins)
    }

    // Local plugins
    if (this.pkg.vuePlugins && this.pkg.vuePlugins.service) {
      const files = this.pkg.vuePlugins.service
      if (!Array.isArray(files)) {
        throw new Error(`Invalid type for option 'vuePlugins.service', expected 'array' but got ${typeof files}.`)
      }
      plugins = plugins.concat(files.map(file => ({
        id: `local:${file}`,
        apply: loadModule(`./${file}`, this.pkgContext)
      })))
    }
    debug('vue:plugins')(plugins)

    const orderedPlugins = sortPlugins(plugins)
    debug('vue:plugins-ordered')(orderedPlugins)

    return orderedPlugins
  }

  async run (name, args = {}, rawArgv = []) {
    // resolve mode
    // prioritize inline --mode
    // fallback to resolved default modes from plugins or development if --watch is defined

View on GitHub (pinned to 7eb93c169c)

Solutions

  1. Wrap the value in an array: `"service": ["./vue-cli-plugin-custom.js"]`.
  2. Each array entry must be a path string resolvable from the project root.

Example fix

// package.json "vue" field — before
"vue": { "vuePlugins": { "service": "./my-plugin.js" } }
// after
"vue": { "vuePlugins": { "service": ["./my-plugin.js"] } }
Defensive patterns

Strategy: type-guard

Validate before calling

const service = (require('./package.json').vue || {}).vuePlugins && require('./package.json').vue.vuePlugins.service
if (service != null && !Array.isArray(service)) {
  throw new Error(`vuePlugins.service must be an array, got ${typeof service}`)
}

Type guard

const isServicePlugins = (v) => v == null || Array.isArray(v)

Prevention

When it happens

Trigger: Setting `"vuePlugins": { "service": "foo.js" }` (a string) or an object/number in package.json's `vue` field instead of an array.

Common situations: Misunderstanding the field shape; copy-paste from docs that showed a single value; hand-editing package.json.

Related errors


AI-assisted analysis of vuejs/vue-cli@7eb93c169c (2026-08-13). Data as JSON: /api/errors/777ddc9415b1a2c9. Report an issue: GitHub.