vuejs/vue-cli · error · Error

transpileDependencies only accepts an array of string or reg

Error message

transpileDependencies only accepts an array of string or regular expressions

What it means

cli-plugin-babel's getDepPathRegex() builds one combined RegExp from the `transpileDependencies` array so the babel loader can decide which node_modules to run through. Each entry is either turned into a `node_modules/<name>/` path (string) or its `.source` is read (RegExp). Any other JS type cannot be converted into a matcher, so the function rejects the whole array.

Source

Thrown at packages/@vue/cli-plugin-babel/index.js:16

const path = require('path')
const babel = require('@babel/core')
const { isWindows } = require('@vue/cli-shared-utils')

function getDepPathRegex (dependencies) {
  const deps = dependencies.map(dep => {
    if (typeof dep === 'string') {
      const depPath = path.join('node_modules', dep, '/')
      return isWindows
        ? depPath.replace(/\\/g, '\\\\') // double escape for windows style path
        : depPath
    } else if (dep instanceof RegExp) {
      return dep.source
    }

    throw new Error('transpileDependencies only accepts an array of string or regular expressions')
  })
  return deps.length ? new RegExp(deps.join('|')) : null
}

/** @type {import('@vue/cli-service').ServicePlugin} */
module.exports = (api, options) => {
  const useThreads = process.env.NODE_ENV === 'production' && !!options.parallel
  const cliServicePath = path.dirname(require.resolve('@vue/cli-service'))

  // try to load the project babel config;
  // if the default preset is used,
  // there will be a VUE_CLI_TRANSPILE_BABEL_RUNTIME env var set.
  // the `filename` field is required
  // in case there're filename-related options like `ignore` in the user config
  babel.loadPartialConfigSync({ filename: api.resolve('src/main.js') })

  api.chainWebpack(webpackConfig => {
    webpackConfig.resolveLoader.modules.prepend(path.join(__dirname, 'node_modules'))

View on GitHub (pinned to 7eb93c169c)

Solutions

  1. Make every entry a string package name (e.g. `'my-lib'`) or a RegExp literal (e.g. `/my-lib/`).
  2. If you wanted a pattern, express it as a RegExp rather than an object.
  3. Remove the offending non-conforming entry from the array.

Example fix

// vue.config.js — before
module.exports = { transpileDependencies: ['my-lib', 42, { name: 'other' }] }
// after
module.exports = { transpileDependencies: ['my-lib', /other/] }
Defensive patterns

Strategy: type-guard

Validate before calling

const deps = config.transpileDependencies || []
const bad = deps.filter(d => typeof d !== 'string' && !(d instanceof RegExp))
if (bad.length) throw new Error(`transpileDependencies entries must be string|RegExp: ${JSON.stringify(bad)}`)

Type guard

const isTranspileDep = (d) => typeof d === 'string' || d instanceof RegExp
const allValid = deps.every(isTranspileDep)

Prevention

When it happens

Trigger: Setting `transpileDependencies` in vue.config.js to an array containing a non-string, non-RegExp value: a number, object, array, boolean, null, or a function.

Common situations: Passing a glob/minimatch object instead of a string; passing a function expecting it to be called; a numeric config copied from elsewhere; YAML/auto-generated config producing a non-string scalar.

Related errors


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