Meituan-Dianping/mpvue · warning

props must be strings when using array syntax.

Error message

props must be strings when using array syntax.

What it means

A component declared props with array syntax but included a non-string entry (e.g. an object or number). Array syntax requires every element to be a prop name string; object syntax is needed for type declarations. Vue warns and skips the invalid entry.

Source

Thrown at src/platforms/mp/runtime/lifecycle.js:115

//       // 这个值必须匹配下列字符串中的一个
//       return ['success', 'warning', 'danger'].indexOf(value) !== -1
//     }
//   }
// }

// core/util/options
function normalizeProps (props, res, vm) {
  if (!props) return
  let i, val, name
  if (Array.isArray(props)) {
    i = props.length
    while (i--) {
      val = props[i]
      if (typeof val === 'string') {
        name = camelize(val)
        res[name] = { type: null }
      } else if (process.env.NODE_ENV !== 'production') {
        warn('props must be strings when using array syntax.')
      }
    }
  } else if (isPlainObject(props)) {
    for (const key in props) {
      val = props[key]
      name = camelize(key)
      res[name] = isPlainObject(val)
        ? val
        : { type: val }
    }
  }

  // fix vueProps to properties
  for (const key in res) {
    if (res.hasOwnProperty(key)) {
      const item = res[key]
      if (item.default) {
        item.value = item.default

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Make every array element a string: props: ['a', 'b'].
  2. If you need types, switch to object syntax: props: { a: String }.
  3. Log/inspect the props array (console.log) to find the non-string element.

Example fix

// before
props: ['title', { type: Number, default: 0 }]
// after
props: { title: String, count: { type: Number, default: 0 } }
Defensive patterns

Strategy: validation

Validate before calling

function assertValidProps (props) {
  if (Array.isArray(props)) {
    props.forEach((p, i) => {
      if (typeof p !== 'string') throw new Error('props[' + i + '] must be a string when using array syntax')
    })
  }
}
assertValidProps(['title', 'count'])

Type guard

const isStringPropsArray = (props) =>
  Array.isArray(props) && props.every(p => typeof p === 'string');

Prevention

When it happens

Trigger: Dev-mode normalization of props: props: ['name', { type: String }] or props: [123] passed to normalizeProps (called by normalizeProperties) during component init/extension.

Common situations: Mixing array and object prop declarations by mistake; dynamically building a props array and accidentally pushing prop definition objects; typos in component factory code.

Related errors


AI-assisted analysis of Meituan-Dianping/mpvue@6c5d78ee04 (2026-09-02). Data as JSON: /api/errors/c827e8b3eb6be565. Report an issue: GitHub.