P
P
Petr Muhurov2019-12-04 14:04:02
JavaScript
Petr Muhurov, 2019-12-04 14:04:02

Why is the Object(...) is not defined error thrown?

I am using webpack.

import { Babushka } from "che-to";

console.log(Babushka); // undefined
Babushka(); // TypeError: Object(...) is not a function

Why is this happening if ? Should an error be thrown in this case ? How it works? I tried to dig the answer in requirejs api, in webpack, in the debugger - I did not find it. PS Found the reason Webpack turns regular codeBabushka === undefinedBabushka is not a function
import { ANY_UNDEFINED_VARIABLE } from "./hello";

console.log("ANY_UNDEFINED_VARIABLE", ANY_UNDEFINED_VARIABLE);

ANY_UNDEFINED_VARIABLE ();

in it
/***/ "./src/index.js":
/*!**********************!*\
  !*** ./src/index.js ***!
  \**********************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _hello__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./hello */ "./src/hello.js");


console.log("ANY_UNDEFINED_VARIABLE", _hello__WEBPACK_IMPORTED_MODULE_0__["ANY_UNDEFINED_VARIABLE"]);

Object(_hello__WEBPACK_IMPORTED_MODULE_0__["ANY_UNDEFINED_VARIABLE"])();


/***/ })

And here is the answer, why do this
webpack

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question