{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/webpack/issues/2066","repository_url":"https://api.github.com/repos/webpack/webpack","labels_url":"https://api.github.com/repos/webpack/webpack/issues/2066/labels{/name}","comments_url":"https://api.github.com/repos/webpack/webpack/issues/2066/comments","events_url":"https://api.github.com/repos/webpack/webpack/issues/2066/events","html_url":"https://github.com/webpack/webpack/issues/2066","id":134515469,"number":2066,"title":"Use CommonsChunkPlugin & `external` config at the same time causes error","user":{"login":"dickeylth","id":2196373,"avatar_url":"https://avatars.githubusercontent.com/u/2196373?v=3","gravatar_id":"","url":"https://api.github.com/users/dickeylth","html_url":"https://github.com/dickeylth","followers_url":"https://api.github.com/users/dickeylth/followers","following_url":"https://api.github.com/users/dickeylth/following{/other_user}","gists_url":"https://api.github.com/users/dickeylth/gists{/gist_id}","starred_url":"https://api.github.com/users/dickeylth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dickeylth/subscriptions","organizations_url":"https://api.github.com/users/dickeylth/orgs","repos_url":"https://api.github.com/users/dickeylth/repos","events_url":"https://api.github.com/users/dickeylth/events{/privacy}","received_events_url":"https://api.github.com/users/dickeylth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-18T08:45:08Z","updated_at":"2016-02-18T09:08:35Z","closed_at":null,"body":"I have external module precompiled by webpack in the seperate js, and my project has multiple entry points, I want the `webpack.optimize.CommonsChunkPlugin` extract common chunks between these entry points, however it seems that it cannot work with `externals` config in webpack.config.js, and throws an error:\r\n\r\n```\r\nUncaught ReferenceError: __WEBPACK_EXTERNAL_MODULE_38__ is not defined\r\n(anonymous function) @ external \"base\":1\r\n__webpack_require__ @ bootstrap 66a520adc59b2bde46c2:564\r\nfn @ bootstrap 66a520adc59b2bde46c2:98\r\nwebpackJsonph5_es6_react__name_.68 @ index.scss:8\r\n__webpack_require__ @ bootstrap 66a520adc59b2bde46c2:564\r\nfn @ bootstrap 66a520adc59b2bde46c2:98\r\nwebpackJsonph5_es6_react__name_.0 @ index.entry.js:16\r\n__webpack_require__ @ bootstrap 66a520adc59b2bde46c2:564\r\nwebpackJsonpCallback @ bootstrap 66a520adc59b2bde46c2:21\r\n(anonymous function) @ index.entry.js:11\r\nwebpackUniversalModuleDefinition @ universalModuleDefinition:9\r\n(anonymous function) @ universalModuleDefinition:10\r\n```\r\n\r\n### webpack.config.js\r\n\r\n```\r\nmodule.exports = {\r\n  entry: entryJSMap,\r\n  context: pwd,\r\n  output: {\r\n    path: path.join(pwd, 'build'),\r\n    publicPath: '/build/',\r\n    filename: '[name].entry.js',\r\n    libraryTarget: 'umd',\r\n    library: [pkgConfig.name, '[name]'],\r\n    umdNamedDefine: true\r\n  },\r\n  module: {\r\n    loaders: [\r\n      ...\r\n    ]\r\n  },\r\n  devtool: '#source-map',\r\n  plugins: [\r\n    new webpack.optimize.CommonsChunkPlugin({\r\n      name: \"commons\",\r\n      // (the commons chunk name)\r\n\r\n      filename: \"commons.js\",\r\n      // (the filename of the commons chunk)\r\n\r\n      // minChunks: 3,\r\n      // (Modules must be shared between 3 entries)\r\n\r\n      //chunks: Object.keys(entryJSMap).concat(['base'])\r\n      // (Only use these entries)\r\n    }),\r\n    new webpack.HotModuleReplacementPlugin()\r\n  ],\r\n  resolve: {\r\n    root: [\r\n      path.resolve('./node_modules'),\r\n      path.resolve('./src/widgets')\r\n    ]\r\n  },\r\n  externals: [\"base\"]\r\n};\r\n```\r\n\r\n### entry 1 js\r\n\r\n```\r\n\"use strict\";\r\nimport {React, ReactDOM} from 'base';\r\n\r\nimport PageHeader from '../../mods/header/index';\r\n\r\nReactDOM.render(<PageHeader subTitle=\"Home page here!\"/>, document.getElementById('J_Page'));\r\n```\r\n\r\n### entry 1 html\r\n\r\n```\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n    <meta charset=\"UTF-8\">\r\n    <title>Home</title>\r\n</head>\r\n<body>\r\n    <div class=\"page-content\" id=\"J_Page\"></div>\r\n    <script src=\"../../widgets/base/seed-react.js\"></script>\r\n    <script src=\"../../commons.js\"></script>\r\n    <script src=\"./index.entry.js\"></script>\r\n</body>\r\n</html>\r\n```\r\n\r\n### entry 2 js\r\n\r\n```\r\n\"use strict\";\r\nimport {React, ReactDOM} from 'base';\r\n\r\nimport PageHeader from '../../mods/header/index';\r\n\r\nReactDOM.render(<PageHeader subTitle=\"Detail page here!\"/>, document.getElementById('J_Page'));\r\n```\r\n\r\n### entry 2 html\r\n\r\n```\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n    <meta charset=\"UTF-8\">\r\n    <title>Detail</title>\r\n</head>\r\n<body>\r\n    <div class=\"page-content\" id=\"J_Page\"></div>\r\n    <script src=\"../../widgets/base/seed-react.js\"></script>\r\n    <script src=\"../../commons.js\"></script>\r\n    <script src=\"./index.entry.js\"></script>\r\n</body>\r\n</html>\r\n```\r\n\r\n### ../../widgets/base/seed-react.js\r\n\r\n```\r\n(function webpackUniversalModuleDefinition(root, factory) {\r\n\tif(typeof exports === 'object' && typeof module === 'object')\r\n\t\tmodule.exports = factory();\r\n\telse if(typeof define === 'function' && define.amd)\r\n\t\tdefine(\"base\", [], factory);\r\n\telse if(typeof exports === 'object')\r\n\t\texports[\"base\"] = factory();\r\n\telse\r\n\t\troot[\"base\"] = factory();\r\n})(this, function() {\r\nreturn /******/ (function(modules) { // webpackBootstrap\r\n/******/ \t// The module cache\r\n/******/ \tvar installedModules = {};\r\n/******/\r\n/******/ \t// The require function\r\n/******/ \tfunction __webpack_require__(moduleId) {\r\n/******/\r\n/******/ \t\t// Check if module is in cache\r\n/******/ \t\tif(installedModules[moduleId])\r\n/******/ \t\t\treturn installedModules[moduleId].exports;\r\n/******/\r\n/******/ \t\t// Create a new module (and put it into the cache)\r\n/******/ \t\tvar module = installedModules[moduleId] = {\r\n/******/ \t\t\texports: {},\r\n/******/ \t\t\tid: moduleId,\r\n/******/ \t\t\tloaded: false\r\n/******/ \t\t};\r\n/******/\r\n/******/ \t\t// Execute the module function\r\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\r\n/******/\r\n/******/ \t\t// Flag the module as loaded\r\n/******/ \t\tmodule.loaded = true;\r\n/******/\r\n/******/ \t\t// Return the exports of the module\r\n/******/ \t\treturn module.exports;\r\n/******/ \t}\r\n/******/\r\n/******/\r\n/******/ \t// expose the modules object (__webpack_modules__)\r\n/******/ \t__webpack_require__.m = modules;\r\n/******/\r\n/******/ \t// expose the module cache\r\n/******/ \t__webpack_require__.c = installedModules;\r\n/******/\r\n/******/ \t// __webpack_public_path__\r\n/******/ \t__webpack_require__.p = \"/build/\";\r\n/******/\r\n/******/ \t// Load entry module and return exports\r\n/******/ \treturn __webpack_require__(0);\r\n/******/ })\r\n/************************************************************************/\r\n/******/ ([\r\n/* 0 */\r\n/***/ function(module, exports, __webpack_require__) {}...\r\n])\r\n});\r\n;\r\n```\r\n\r\nLooking forward from your explanation and solution, thank you!"},"comment":{"url":"https://api.github.com/repos/webpack/webpack/issues/comments/185612066","html_url":"https://github.com/webpack/webpack/issues/2066#issuecomment-185612066","issue_url":"https://api.github.com/repos/webpack/webpack/issues/2066","id":185612066,"user":{"login":"jrs320","id":6623047,"avatar_url":"https://avatars.githubusercontent.com/u/6623047?v=3","gravatar_id":"","url":"https://api.github.com/users/jrs320","html_url":"https://github.com/jrs320","followers_url":"https://api.github.com/users/jrs320/followers","following_url":"https://api.github.com/users/jrs320/following{/other_user}","gists_url":"https://api.github.com/users/jrs320/gists{/gist_id}","starred_url":"https://api.github.com/users/jrs320/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrs320/subscriptions","organizations_url":"https://api.github.com/users/jrs320/orgs","repos_url":"https://api.github.com/users/jrs320/repos","events_url":"https://api.github.com/users/jrs320/events{/privacy}","received_events_url":"https://api.github.com/users/jrs320/received_events","type":"User","site_admin":false},"created_at":"2016-02-18T09:08:35Z","updated_at":"2016-02-18T09:08:35Z","body":"why no people 鸟 you"}}