Skip to content

Uncaught TypeError: Cannot read property 'call' of undefined #959

Closed

Description

@kfancy

I'm having an issue with webpack where if I stop watching and restart, it will build just fine, but if I edit a file and save it, the incremental build fails with this error:

Uncaught TypeError: Cannot read property 'call' of undefined

Hunting it down there's a module that does not get included in the incremental change build. Best guess is the path followed to re-make the bundle file is not being followed correctly. Upon re-running (stop and start), the missing module is included.

webpack.config.js (module names changed to protect the innocent):

var webpack = require("webpack"),
    path = require('path')
    ;

module.exports = {
  entry: {
    Entry1: "./app/Entry1.js",
    Entry2: "./app/Entry2.js",
    Entry3: "./app/Entry3.js",
    Entry4: "./app/Entry4.js",
    Entry5: "./app/Entry5.js",
    Entry6: "./app/Entry6.js",
    Entry7: "./app/Entry7.js",
    Entry8: "./app/Entry8.js",
  },
  output: {
    path: path.join(__dirname, "public/js"),
    filename: "[name].bundle.js",
    chunkFilename: "[id].chunk.js"
  },
  module: {
    loaders: [
      {test: /\.js$/, loader: 'jsx-loader'}
    ]
  },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin("shared.js")
    ]
};

Activity

  1. sokra commented on Apr 9, 2015

    @sokra
    Member

    Is it really a incorrect bundle/chunk file or is the file in the browser cache just old?

  2. sokra commented on Apr 10, 2015

    @sokra
    Member

    Maybe it's fixed... Please reopen if still an issue with 1.8.4

  3. kfancy commented on Apr 10, 2015

    @kfancy
    Author

    It is really an incorrect bundle/chunk, I've flushed the browser to make sure of that.
    Essentially, the module trying to be required is 100% missing on an incremental watch build.
    Doesn't happen all the time.

    For instance, using reactjs key mirror, on a list of constants, I'd require('react/lib/keyMirror'). On first build, no problem. On watch build, keyMirror module is completely missing from the file where it used to be.

  4. makedonian commented on Apr 13, 2015

    @makedonian

    I'm still having this issue with 1.8.4. Pretty much the same setup as @kfancy, except my loader is jsx-loader?harmony

    Worth mentioning is that it started happening after upgrading to react 0.13.1. I was porting code from 0.12 and didn't have issues even with webpack 1.7.2. Upgraded react, started having the issue, upgraded webpack to 1.8.4, and the issue still persist. I even removed the CommonsChunckPlugin to see if that would fix the problem, but no luck with that either.

    I'm also getting random errors like Uncaught Error: Cannot find module "classnames" every now and then, only when running --watch.

  5. DanielApt commented on Jul 3, 2015

    @DanielApt

    I'm still seeing this issue. Using the latest version v1.10.1

    First build works fine, but incremental builds fail. I get the following error from my bundle:
    Uncaught TypeError: Cannot read property 'apply' of undefined

    It seems to break on the usage of apply in this function.

    function(modules) {
        // Check all modules for deduplicated modules
        for(var i in modules) {
            if(Object.prototype.hasOwnProperty.call(modules, i)) {
                switch(typeof modules[i]) {
                case "function": break;
                case "object":
                    // Module can be created from a template
                    modules[i] = (function(_m) {
                        var args = _m.slice(1), fn = modules[_m[0]];
                        return function (a,b,c) {
                            fn.apply(this, [a,b,c].concat(args)); // Breaks here
                        };
                    }(modules[i]));
                    break;
                default:
                    // Module is a copy of another module
                    modules[i] = modules[modules[i]];
                    break;
                }
            }
        }
        return modules;
    }

    The hashes of the builds are different.

  6. DanielApt commented on Jul 3, 2015

    @DanielApt

    It has something do with our entry points:

    We have issues when we use:

    context: __dirname + '/project_name/static/js',
    entry: {
            'static/dist/js/app': './components/app.js',
            'static/dist/js/log-in': './components/log-in.js',
            'static/dist/js/widget-a': './widgets/widget-a.js',
            'tests/testBundle': '../../tests/test.js', // removing this line fixes things
        },
        output: {
            path: __dirname + '/project_name',
            filename: '[name].js',
            sourceMapFileName: '[file].map'
        },

    When removing testBundle things work nicely. Strangely enough the bundle throwing the error is actually app.js

    PS: Sorry for the strange file system. We should address this once we have the chance.

  7. DanielApt commented on Jul 23, 2015

    @DanielApt

    @sokra could you re-open this issue?

  8. reopened this on Jul 23, 2015
  9. sokra commented on Jul 23, 2015

    @sokra
    Member

    Could you try upgrading to the lasted version?

  10. DanielApt commented on Jul 23, 2015

    @DanielApt

    Done. Still an issue.

  11. jeffutter commented on Aug 11, 2015

    @jeffutter

    I seem to be having this issue as well. It has been happening for the past few days, not sure if it was a webpack change or a code change that caused this. Let me know if I can help provide any info to track it down.

  12. Cap32 commented on Aug 13, 2015

    @Cap32

    😭I'm still seeing this issue. Using the latest version v1.11.0

  13. fxmaxvl commented on Aug 27, 2015

    @fxmaxvl

    Is there any progress on this issue?

  14. owais commented on Aug 30, 2015

    @owais

    I'm facing this issue only when I use ExtractTextPlugin + SplitByPathPlugin (or split by name). It goes away if I remove either one of them.

  15. 257 remaining items

  16. Ys-sudo commented on May 15, 2020

    @Ys-sudo

    My story with it:

    webpack.prod.js - bug:

    module.exports = {
      entry: {
     app: [
       'react-hot-loader/patch',
       'webpack/hot/only-dev-server',
       './src/index.js'
     ],
    },
        output: {
            path:__dirname+ '/dist/',
            filename: "bundle.js",
            publicPath: '/'
        },
        devServer: {
            inline: false,
            contentBase: "./dist",
        },
        module: {
          loaders: [
            {
                    test: /\.js$/,
                    exclude:/node_modules/,        //exclude loader
                    loader: "babel-loader"
                },
                {
                    test: /\.css$/,        //css
                    loader:"style-loader!css-loader"    // style
            ]
        }
    
    };
    
    

    webpack.prod.js - fix:

    comment out second line in app array. webpack/hot

    //'webpack/hot/only-dev-server',

  17. beejaz commented on Aug 24, 2020

    @beejaz

    @apertureless
    I am using version 3. But version 4 also works if I remove the <style></style> tags from the components.

    I had the same problem with this error message. I removed a empty style tag in my newly added component that cause the issue:

    <style scoped>
    </style>
    

    After that it worked again!

  18. restuwahyu13 commented on Sep 14, 2020

    @restuwahyu13

    follow step by step this solution for fix this problem, working with me using webpack 4

    1.STEP ONE
    output: {
    library: '[name]',
    umdNamedDefine: false
    }

    optimization: {
    concatenateModules: false,
    providedExports: false,
    usedExports: false
    }

    1. STEP TWO
      remove symlink and caheWithContenxt

    2. STEP THREE
      remove react hot module or disable this for production

    3. STEP FOUR
      remove old project name in heroku, after remove old project create new project name

  19. softmarshmallow commented on Oct 4, 2020

    @softmarshmallow

    TypeError: Cannot read property 'Reflect' of undefined when using reflect-metadata

  20. EugeneJang commented on Mar 18, 2021

    @EugeneJang

    never ending..

  21. florton commented on Mar 31, 2021

    @florton

    Was able to fix it with a combination of chunk hashing and webpack route prefetching. The prefetching logic prevents the client from requesting outdated chunks, and the chunk hashing forces the chunks to update once new ones are available server side. With only one or the other, chunks either crash or fail to update. I believe this is because we have code splitting implemented in our react appRoot.

    I would also like to note the often proposed solution of adding chunksSortMode: 'dependency' completely broke our update cycle and prevented the app from properly updating at all. I dont recommend it for production code.

    My fix: (Webpack 4.46.0 & react 16.14.0 with HtmlWebpackPlugin)

    Note: This solution only worked perfectly after the second app update as the prefetching logic must be live on the client to prevent loading outdated chunks.

    Edit: This did not entirely fix our issue and the problem persists :(

  22. Superwzw commented on Jun 25, 2021

    @Superwzw

    I also encountered a similar problem in my project. After troubleshooting for a long time, I found that it might be a problem with scope hoisting enabled. Finally, I temporarily solved this problem by commenting out optimization.concatenateModules: true in the wepack configuration

  23. alexander-akait commented on Jun 25, 2021

    @alexander-akait
    Member

    @Superwzw What is webpack version?

  24. namnguyen2091 commented on Jul 2, 2021

    @namnguyen2091

    just clear cache in my case

  25. JustAnotherSoftwareDeveloper commented on Sep 2, 2021

    @JustAnotherSoftwareDeveloper

    Why is this closed? This is still an issue

  26. WesleyHendon commented on Sep 9, 2021

    @WesleyHendon

    I can confirm this is still an issue.

    I am using webpack 5.30 and vue 2.6.11

    I am trying to implement lazy loading on our already existing vue app to reduce our bundle size. Here is how I am importing the component:

    const ManageSupport = () => import(/* webpackChunkName: "view-support" */ 'components/helpdesk/view-support')

    The chunk is created successfully, based on this webpack output: asset view-support.js 29.4 KiB [emitted] (name: view-support)

    When trying to navigate to that route, I keep getting (consistently) the error
    `[vue-router] Failed to resolve async component default: TypeError: Cannot read property 'call' of undefined

    TypeError: Cannot read property 'call' of undefined
    at webpack_require (main.js:26989)
    at Function.fn (main.js:27159)`

    A snippet from main.js where the error is thrown:

    // Execute the module function
    /******/ 		try {
    /******/ 			var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ };
    /******/ 			__webpack_require__.i.forEach(function(handler) { handler(execOptions); });
    /******/ 			module = execOptions.module;
    /******/ (error here)execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
    /******/ 		} catch(e) {
    /******/ 			module.error = e;
    /******/ 			throw e;
    /******/ 		}
    

    My webpack configuration:

    const webpack = require('webpack');
    const { VueLoaderPlugin } = require("vue-loader")
    const TerserPlugin = require("terser-webpack-plugin")
    const CompressionPlugin = require('compression-webpack-plugin')
    const MiniCssExtractPlugin = require('mini-css-extract-plugin')
    var FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
    
    const bundleOutputDir = './wwwroot/dist';
    
    module.exports = (env) => {
        const isDevBuild = env.prod != 'true';
        console.log("Starting webpack " + (isDevBuild ? "Dev" : "Prod") + " Build (main.js)")
        return {
            mode: isDevBuild ? 'development' : 'production',
            target: isDevBuild ? false : ['web', 'es5'],
            entry: './ClientApp/boot-app.js',
            output: {
                path: path.resolve(__dirname, bundleOutputDir),
                filename: '[name].js',
                publicPath: '/dist/'
            },
            resolve: {
                alias: {
                    'vue$': 'vue/dist/vue',
                    'components': path.resolve(__dirname, './ClientApp/components'),
                    'views': path.resolve(__dirname, './ClientApp/views'),
                    'utils': path.resolve(__dirname, './ClientApp/utils')
                },
                extensions: ["*", ".js", ".vue", ".json"]
            },
            module: {
                rules: [
                    // Vue
                    { test: /\.vue$/, loader: "vue-loader", exclude: /node_modules/ },
    
                    // CSS
                    { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
    
                    {
                        test: /\.m?js/,
                        resolve: {
                            fullySpecified: false
                        }
                    },
    
                    // JavaScript
                    {
                        test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader',
                        exclude: file => (
                            /node_modules/.test(file) &&
                            !/\.vue\.js/.test(file)
                        )
                    },
    
                    { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
                ],
            },
            plugins: [
    
                new MiniCssExtractPlugin({ filename: "site.css" }),
    
                new webpack.DllReferencePlugin({
                    context: __dirname,
                    manifest: path.join(__dirname, 'wwwroot', 'dist', 'vendor-manifest.json')
                }),
    
                new VueLoaderPlugin(),
    
                new FriendlyErrorsWebpackPlugin(),
    
            ].concat(
                isDevBuild ? [
    
                    // Dev-only dependencies
    
                ] : [
    
                        // Prod-only dependencies
    
                        new CompressionPlugin({
                            filename: '[path][base]',
                            test: /\.(js|css|svg|json)$/,
                            deleteOriginalAssets: true
                        })
    
                    ]),
            optimization: isDevBuild ? {} : {
                minimize: true,
                minimizer: [new TerserPlugin({
                    test: /\.js(\?.*)?$/i,
                })]
            },
            cache: true
        }
    }
    

    My package.json

    {
        "scripts": {
            "build": "cross-env webpack --progress --no-devtool --config webpack.config.js --env prod=true",
            "start": "NODE_OPTIONS=--max_old_space_size=4096 webpack serve --progress --hot --hot-only --config webpack.config.js --content-base 'wwwroot' --env prod=false",
            "vendor": "webpack --config webpack.config.vendor.js --env prod=false --progress --stats-error-details",
            "app": "cross-env NODE_OPTIONS=--max_old_space_size=4096 webpack --progress --config webpack.config.js --env prod=false",
            "help": "webpack --help"
        },
        "dependencies": {
            "@babel/plugin-transform-runtime": "^7.13.10",
            "@fortawesome/fontawesome-svg-core": "^1.2.28",
            "@fortawesome/free-brands-svg-icons": "^5.13.0",
            "@fortawesome/pro-light-svg-icons": "^5.13.0",
            "@fortawesome/pro-regular-svg-icons": "^5.13.0",
            "@fortawesome/pro-solid-svg-icons": "^5.13.0",
            "@fortawesome/vue-fontawesome": "^0.1.9",
            "@microsoft/signalr": "=3.1.6",
            "axios": "^0.21.1",
            "core-js": "^2.6.11",
            "epsg-index": "^1.0.0",
            "font-awesome": "^4.6.3",
            "lodash": "^4.17.19",
            "moment": "^2.24.0",
            "moment-mini": "^2.24.0",
            "vue": "^2.6.11",
            "vue-router": "^2.1.1",
            "vue-template-compiler": "^2.6.11",
            "vuex": "^2.1.1",
            "vuex-persistedstate": "^2.5.4",
            "vuex-router-sync": "^4.0.1"
        },
        "devDependencies": {
            "@babel/core": "^7.13.14",
            "@babel/plugin-proposal-class-properties": "^7.13.0",
            "@babel/preset-env": "^7.13.12",
            "babel-loader": "^8.2.2",
            "bootstrap": "^3.3.6",
            "compression-webpack-plugin": "^7.1.2",
            "cross-env": "^3.1.3",
            "css-loader": "^5.2.1",
            "event-source-polyfill": "^0.0.7",
            "friendly-errors-webpack-plugin": "^1.7.0",
            "file-loader": "^6.2.0",
            "html-webpack-plugin": "^5.3.1",
            "jquery": "^2.2.1",
            "lodash-webpack-plugin": "^0.11.5",
            "mini-css-extract-plugin": "^1.4.1",
            "optimize-css-assets-webpack-plugin": "^5.0.4",
            "postcss-loader": "^5.2.0",
            "postcss-preset-env": "^6.7.0",
            "scope-loader": "^1.0.3",
            "spectacle-docs": "^1.0.7",
            "style-loader": "^2.0.0",
            "url-loader": "^0.5.7",
            "vue-loader": "^15.9.6",
            "webpack": "^5.30.0",
            "webpack-cli": "^4.6.0",
            "webpack-dev-server": "^3.11.2",
            "webpack-hot-middleware": "^2.12.2"
        }
    }
    
  27. alexander-akait commented on Sep 9, 2021

    @alexander-akait
    Member

    Update webpack to the latest version, also please update webpack-dev-server

  28. Superwzw commented on Dec 28, 2021

    @Superwzw

    @alexander-akait my webpack version is:
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12",
    "webpack-dev-server": "^3.11.2"

  29. alexander-akait commented on Dec 28, 2021

    @alexander-akait
    Member

    Can you migrate on webpack v5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions