webpack-deep-scope-analysis-plugin icon indicating copy to clipboard operation
webpack-deep-scope-analysis-plugin copied to clipboard

"Cannot read property 'call' of undefined" in bootstrap

Open OfirArviv opened this issue 6 years ago • 13 comments
trafficstars

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

OfirArviv avatar Dec 10 '18 15:12 OfirArviv

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.

vincentdchan avatar Jan 06 '19 10:01 vincentdchan

The same error, webpack 4.30.0

ksky521 avatar Apr 18 '19 03:04 ksky521

// 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()]
};

ksky521 avatar Apr 18 '19 03:04 ksky521

The same error, webpack 4.30.0

+1

xinlanlan avatar Jul 02 '19 09:07 xinlanlan

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.

vincentdchan avatar Jul 04 '19 06:07 vincentdchan

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 avatar Jul 08 '19 13:07 sokra

@sokra So which version fixes this problem on npm? I can update the dependency in package.json.

vincentdchan avatar Jul 08 '19 14:07 vincentdchan

@sokra I've tried to upgrade webpack to 4.35.3, but it seems that it's unsolved.

vincentdchan avatar Jul 14 '19 03:07 vincentdchan

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.

sokra avatar Jul 27 '19 13:07 sokra

I have published a new version.

Thanks @sokra . I made a mistake.

vincentdchan avatar Jul 28 '19 02:07 vincentdchan

webpack-deep-scope-plugin 1.6.2 webpack 4.40.2 还是有这个问题 Uncaught TypeError: Cannot read property 'call' of undefined

hmz5 avatar Sep 17 '19 07:09 hmz5

@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: image

Code bundled in prod mode: image

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.

vincentdchan avatar Sep 28 '19 18:09 vincentdchan

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!

gustavoschmidt avatar Apr 14 '20 15:04 gustavoschmidt