使用Webpack+Node构建React项目时遇Cannot read property 'call' of undefined错误求助
That error typically pops up when Webpack's runtime can't properly resolve or execute a module, often tied to incorrect chunk configuration or ordering. Let's walk through the most likely fixes based on your provided config:
1. Complete the Manifest CommonsChunkPlugin Configuration
Your code cuts off mid-manifest chunk setup, which is critical for separating the Webpack runtime from your vendor bundle. Without this, the runtime might get tangled with vendor code, leading to execution errors. Here's the full, correct setup:
// Extract CSS new ExtractTextPlugin({ filename: 'css/[contenthash].css', allChunks: true }), // Extract third-party vendors new webpack.optimize.CommonsChunkPlugin({ name: "vendor", minChunks: module => module.context && module.context.indexOf('node_modules') !== -1 }), // Extract Webpack runtime into manifest (must come AFTER vendor chunk) new webpack.optimize.CommonsChunkPlugin({ name: "manifest", minChunks: Infinity }),
The minChunks: Infinity ensures only the runtime is pulled into the manifest chunk, which needs to load first to bootstrap your app correctly.
2. Verify Script Order in Your HTML File
If your HTML loads the chunks in the wrong order, the runtime (in manifest) won't be available when vendor or app code tries to execute. Make sure your script tags follow this sequence:
<script src="/manifest.js"></script> <script src="/vendor.js"></script> <script src="/app.js"></script> <!-- Your main app chunk -->
3. Check ExtractTextPlugin and Webpack Version Compatibility
Since you're using CommonsChunkPlugin, you're on Webpack 3 or earlier. Ensure your extract-text-webpack-plugin version matches:
- For Webpack 3: Use
extract-text-webpack-plugin@3.x - If you accidentally installed a newer version (like 4+), it won't work with Webpack 3. Run this to fix:
npm install extract-text-webpack-plugin@3.0.2 --save-dev
4. Clear Stale Build Assets
Sometimes cached or corrupted chunk files cause this error. Delete your entire dist (or output) folder, then rebuild from scratch:
rm -rf dist && npm run build
5. Validate Vendor Module Exports
In rare cases, a third-party module in node_modules might have an invalid export. Try temporarily removing non-critical dependencies one by one and rebuilding to isolate the problematic module.
If none of these fix the issue, feel free to share your full webpack.config.js and the full error stack trace—those details will help narrow it down further.
内容的提问来源于stack exchange,提问作者Matarishvan

