{"record":{"id":"1af7e37d676f890f","repo":"Meituan-Dianping/mpvue","slug":"webpack-config-output-librarytarget-should-be-c","errorCode":null,"errorMessage":"webpack config `output.libraryTarget` should be \"commonjs2\".","messagePattern":"webpack config `output\\.libraryTarget` should be \"commonjs2\"\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/server/webpack-plugin/util.js","lineNumber":13,"sourceCode":"const { red, yellow } = require('chalk')\n\nconst prefix = `[vue-server-renderer-webpack-plugin]`\nconst warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\\n`))\nconst tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\\n`))\n\nexport const validate = compiler => {\n  if (compiler.options.target !== 'node') {\n    warn('webpack config `target` should be \"node\".')\n  }\n\n  if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') {\n    warn('webpack config `output.libraryTarget` should be \"commonjs2\".')\n  }\n\n  if (!compiler.options.externals) {\n    tip(\n      'It is recommended to externalize dependencies in the server build for ' +\n      'better build performance.'\n    )\n  }\n}\n\nexport { isJS, isCSS } from '../util'\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/src/server/webpack-plugin/util.js#L1-L25","documentation":"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.","triggerScenarios":"Thrown at src/server/webpack-plugin/util.js:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set output: { libraryTarget: 'commonjs2' } in the server webpack config","Ensure the server bundle entry is compiled with that target so the renderer can require() it","If multiple outputs exist, apply commonjs2 only to the server-side build configuration"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}