'chrome dev tool bug for “Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization”
I have a problem with my webpack project. During my attempt to upgrade webpack from 4.44 to 5.56, the following problem occurred:
Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
This is the code of the class were i am trying to import :
import Logger from '../../core/libs/logger';
import $ from 'jquery';
import {globalArray} from './jscdkClient';
const util = {
brokerSupportApplication: function() {}
...
}
export default util;
After comparing the code output before and after the upgrade, I found the problem. webpack@5 has an extra line in the file defining default. this is code:
/***/ 15189:
/*!***********************************************!*\
!*** ./webapp/webclient/shared/jscdk/util.ts ***!
\***********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) // <---- The error is reported from here**
/* harmony export */ });
/* harmony import */ var _core_libs_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../core/libs/logger */ 36986);
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! jquery */ 16346);
/* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _jscdkClient__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./jscdkClient */ 67380);
/*********************************************************
* Copyright (C) 2014-2018 VMware, Inc. All rights reserved.
*********************************************************/
I don't think this is a problem created by circular dependency. In my actual usage, the structure of the util.ts involved is as follows
a.js
| --- b.js (import util from 'uitl.ts')
| --- | --- c.js
| --- | --- | --- d.js (import util from 'util.ts')
Why is this happening? How should I solve this problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
