diff --git a/app/react/src/server/babel_config.js b/app/react/src/server/babel_config.js index 7ed0bc5ca030..8eab74ed4283 100644 --- a/app/react/src/server/babel_config.js +++ b/app/react/src/server/babel_config.js @@ -66,11 +66,19 @@ export default function(configDir) { } const finalConfig = babelConfig || defaultConfig; - finalConfig.plugins = finalConfig.plugins || []; - finalConfig.plugins.push([ - require.resolve('babel-plugin-react-docgen'), - { DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES' }, - ]); + // Ensure plugins are defined or fallback to an array to avoid empty values. + const babelConfigPlugins = finalConfig.plugins || []; + const extraPlugins = [ + [ + require.resolve('babel-plugin-react-docgen'), + { + DOC_GEN_COLLECTION_NAME: 'STORYBOOK_REACT_CLASSES', + }, + ], + ]; + // If `babelConfigPlugins` is not an `Array`, calling `concat` will inject it + // as a single value, if it is an `Array` it will be spreaded. + finalConfig.plugins = [].concat(babelConfigPlugins, extraPlugins); return finalConfig; }