webpack-deep-scope-analysis-plugin
webpack-deep-scope-analysis-plugin copied to clipboard
"Cannot read property 'call' of undefined" in bootstrap
Hi,
I'm trying to use the plugin, but when running it I get an exception in the bootstrap process. The relevant function is:
// The require function
function __webpack_require__(moduleId) {
// Check if module is in cache
if(installedModules[moduleId]) {
return installedModules[moduleId].exports;
}
// Create a new module (and put it into the cache)
var module = installedModules[moduleId] = {
i: moduleId,
l: false,
exports: {}
};
// Execute the module function
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); --->>> Exception is thrown here.
// Flag the module as loaded
module.l = true;
// Return the exports of the module
return module.exports;
}
The module is missing.
The function is called because of import isPlainObject from 'lodash-es/isPlainObject';
Which if following the stack is referenced somewhere in the "react-redux" module
I use UglifyJsPlugin with dead code elimination and HashedModuleIdsPlugin, but they are not the problem, as I get the error even when removing them.
Would appreciate any help
Thanks
Can you provide the versions of webpack and the plugin? And it would be better if you can provide a Github Repo which can trigger the error.
The same error, webpack 4.30.0
// lodash.js
import lodash from 'lodash-es';
function isArray(obj) {
return lodash.isArray(obj);
}
function isNull(obj) {
return null === obj;
}
export {isArray, isNull};
// main.js
import {isNull} from './lodash';
console.log(isNull(1));
//webapck.config
const WebpackDeepScopeAnalysisPlugin = require('webpack-deep-scope-plugin').default;
const HTMLWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'production',
devtool: 'source-map',
entry: {
main: './src/main.js'
},
plugins: [new WebpackDeepScopeAnalysisPlugin(), new HTMLWebpackPlugin()]
};
The same error, webpack 4.30.0
+1
I've tried the example, the code does break. Actually, this plugin return right informations to webpack, but webpack generates unexpected code. I've tried to communicate with webpack team about this issue.
The problematic code in lodash-es is:
import root from './_root.js';
/** Built-in value references. */
var Symbol = root.Symbol;
export default Symbol;
which generates this code:
"use strict";
/* harmony import */ var _root_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_root.js */ "./node_modules/lodash-es/_root.js");
/** Built-in value references. */
var Symbol = /* unused export default */ undefined.Symbol;
/* unused harmony default export */ var _unused_webpack_default_export = (Symbol);
So somehow the analysis thinks root is unused, while it's really used.
This has already been fixed in the master branch, but the published code on npm doesn't match the tag in the repo (very bad 😢 ).
@sokra So which version fixes this problem on npm? I can update the dependency in package.json.
@sokra I've tried to upgrade webpack to 4.35.3, but it seems that it's unsolved.
This has already been fixed in the master branch, but the published code on npm doesn't match the tag in the repo (very bad 😢 ).
I meant on the master branch of this repo.
I have published a new version.
Thanks @sokra . I made a mistake.
webpack-deep-scope-plugin 1.6.2 webpack 4.40.2 还是有这个问题 Uncaught TypeError: Cannot read property 'call' of undefined
@sokra Although webpack 5 have integrated deep scope analysis. It seems that this issue is not the problem of the plugin.
Code bundled in dev mode:

Code bundled in prod mode:

In dev mode, loadash is eliminated to undefined, the code run normally. But in prod mode, there is a r(463), and the code break. 463 represents loadash.default, which should be eliminated(it has been eliminated in dev mode, so it's saying that the plugin work normally!).
I have checked the output of the plugin, it's ok. You can try it on the master branch.
I had a similar problem compiling react-bootstrap#0.32.4. The Radio component is undefined when using this plugin on production mode (but it works when I disable the plugin). I couldn't figure out the part of the code responsible for it. Any tips on how to debug? Thanks!