vuejs/vue-cli · error · Error
Error loading ${fileConfigPath}: should export an object or
Error message
Error loading ${fileConfigPath}: should export an object or a function that returns object. What it means
resolveUserConfig loads vue.config.js. Its export must be a plain object, or a function that returns one (functions are called and the result re-checked). After that, the value must be a non-null object; a string, number, array, boolean, or a function returning null/undefined is rejected.
Source
Thrown at packages/@vue/cli-service/lib/util/resolveUserConfig.js:30
function removeSlash (config, key) {
if (typeof config[key] === 'string') {
config[key] = config[key].replace(/\/$/g, '')
}
}
module.exports = function resolveUserConfig ({
inlineOptions,
pkgConfig,
fileConfig,
fileConfigPath
}) {
if (fileConfig) {
if (typeof fileConfig === 'function') {
fileConfig = fileConfig()
}
if (!fileConfig || typeof fileConfig !== 'object') {
throw new Error(
`Error loading ${chalk.bold(fileConfigPath)}: ` +
`should export an object or a function that returns object.`
)
}
}
// package.vue
if (pkgConfig && typeof pkgConfig !== 'object') {
throw new Error(
`Error loading Vue CLI config in ${chalk.bold(`package.json`)}: ` +
`the "vue" field should be an object.`
)
}
let resolved, resolvedFrom
if (fileConfig) {
const configFileName = path.basename(fileConfigPath)
if (pkgConfig) {View on GitHub (pinned to 7eb93c169c)
Solutions
- Export an object: `module.exports = { ... }`.
- If using a function, ensure every path returns a non-null object: `module.exports = () => ({ ... })`.
Example fix
// vue.config.js — before
module.exports = () => { configureWebpack: {} }
// after
module.exports = () => ({ configureWebpack: {} }) Defensive patterns
Strategy: type-guard
Validate before calling
const cfg = require('./vue.config.js')
const resolved = typeof cfg === 'function' ? cfg() : cfg
if (!resolved || typeof resolved !== 'object' || Array.isArray(resolved)) {
throw new Error('vue.config.js must export an object or a function returning an object')
} Type guard
const isVueConfig = (c) => typeof c === 'function' || (typeof c === 'object' && c !== null && !Array.isArray(c))
Prevention
- Default-export an object literal in vue.config.js.
- If using a function, ensure every return path yields a non-null object.
When it happens
Trigger: vue.config.js exporting a primitive (`module.exports = '...'`), an array, or a function that returns null/undefined/a non-object.
Common situations: Missing/wrong default export; a function config with a code path that returns undefined; accidentally exporting a config builder without calling it.
Related errors
- transpileDependencies only accepts an array of string or reg
- Invalid type for option 'vuePlugins.service', expected 'arra
- Error loading Vue CLI config in package.json: the "vue" fiel
- Cannot find polyfill ${item}, please refer to 'core-js-compa
- ${workboxPluginMode} is not a supported Workbox webpack plug
AI-assisted analysis of vuejs/vue-cli@7eb93c169c (2026-08-13).
Data as JSON: /api/errors/76be357a11d7bd4e.
Report an issue: GitHub.