Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Uncaught TypeError: Cannot read property 'call' of undefined" in webpack?

Basically I'm setting up webpack and when I tried getting dev-server in development mode in webpack, I ran into this Error.

I tried following some instructions in other things, tried from beginning twice, but still getting the same error. I can't figure out what I am doing wrong here. If anyone has solution onto this issue, I'd very much appreciate that. Thanks.

Error I'm getting:

bundle.js:20 Uncaught TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (bundle.js:20)
    at eval (index.js:2)
    at Object../src/js/index.js (bundle.js:357)
    at __webpack_require__ (bundle.js:20)
    at eval (webpack:///multi_(:8080/webpack)-dev-server/client?:2:18)
    at Object.0 (bundle.js:368)
    at __webpack_require__ (bundle.js:20)
    at bundle.js:69
    at bundle.js:72

Specifics of error:

// Execute the module function
/******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

webpack.config.js:

const path = require('path');

module.exports = {
    entry: './src/js/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/bundle.js'
    },
    devServer: {
        contentBase: './dist'
    }
};

package.json:

{
    "name": "forkify",
    "version": "1.0.0",
    "description": "forkify project",
    "main": "index.js",
    "scripts": {
        "dev": "webpack --mode development",
        "build": "webpack --mode production",
        "start": "webpack-dev-server --mode development --open"
    },
    "author": "Jonas Schmedtmann",
    "license": "ISC",
    "devDependencies": {
        "webpack": "^4.2.0"
    },
    "dependencies": {
        "webpack-cli": "^2.1.5",
        "webpack-dev-server": "^3.4.1"
    }
}

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script src="js/bundle.js"></script>
</body>
</html>

I expect any solutions to this.

like image 615
Jenny Yang Avatar asked May 31 '19 08:05

Jenny Yang


1 Answers

I encountered the same issue yesterday and went through a lot of discussions online. Few suggested that it is due to a bug in webpack-dev-server and few suggested it is due to improper imports of the chunks. But none of it was the case with me as I was generating a single chunk file. What worked for me is to remove the node_modules folder completely and do a fresh npm install. Good luck.

like image 187
AshishAgrahari Avatar answered Jan 02 '23 22:01

AshishAgrahari