Meituan-Dianping/mpvue · error

webpack config `output.libraryTarget` should be "commonjs2".

Error message

webpack config `output.libraryTarget` should be "commonjs2".

What it means

Second check in the SSR webpack plugin's validate(): it warns when compiler.options.output.libraryTarget exists and is not 'commonjs2'. The server bundle is consumed by the Node renderer via require(), which needs the CommonJS2 module exports convention; any other libraryTarget (amd, umd, var...) makes the bundle's exports inaccessible to vue-server-renderer and the render will fail to find the app manifest.

Source

Thrown at src/server/webpack-plugin/util.js:13

const { red, yellow } = require('chalk')

const prefix = `[vue-server-renderer-webpack-plugin]`
const warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\n`))
const tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`))

export const validate = compiler => {
  if (compiler.options.target !== 'node') {
    warn('webpack config `target` should be "node".')
  }

  if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') {
    warn('webpack config `output.libraryTarget` should be "commonjs2".')
  }

  if (!compiler.options.externals) {
    tip(
      'It is recommended to externalize dependencies in the server build for ' +
      'better build performance.'
    )
  }
}

export { isJS, isCSS } from '../util'

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Set output: { libraryTarget: 'commonjs2' } in the server webpack config
  2. Ensure the server bundle entry is compiled with that target so the renderer can require() it
  3. If multiple outputs exist, apply commonjs2 only to the server-side build configuration
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/server/webpack-plugin/util.js:13 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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