Javascript 如何解决此问题:无法访问';计算熵';在初始化之前?

Javascript 如何解决此问题:无法访问';计算熵';在初始化之前?,javascript,reactjs,Javascript,Reactjs,我正在开发一个大型CRA单页应用程序。它已经运行了好几个月,正常的bug通常是可以修复的。几周前,它失败了,只是挂在启动页面上旋转一圈。没有命中代码,因此没有断点工作。我做了很多关于导入和导出所有文件的实验,认为这是根本原因。最后我想做一个构建并运行它。它确实通过了初始屏幕并生成了一个异常。第一个已修复,但现在我发现在初始化错误之前无法访问“calculationEntry”。我使用的是VSCode,launch.json配置为: "name": "Chrome

我正在开发一个大型CRA单页应用程序。它已经运行了好几个月,正常的bug通常是可以修复的。几周前,它失败了,只是挂在启动页面上旋转一圈。没有命中代码,因此没有断点工作。我做了很多关于导入和导出所有文件的实验,认为这是根本原因。最后我想做一个构建并运行它。它确实通过了初始屏幕并生成了一个异常。第一个已修复,但现在我发现在初始化错误之前无法访问“calculationEntry”。我使用的是VSCode,launch.json配置为:

  "name": "Chrome React",
  "type": "chrome",
  "request": "launch",
  "sourceMaps": true,
  "url": "http://localhost:3000",
  "webRoot": "${workspaceRoot}/src",
  "userDataDir": "${workspaceRoot}/.chrome",
  "sourceMapPathOverrides": {
    "webpack:///src/*": "${webRoot}/*"
  },
  "breakOnLoad": true
我不能显示示例代码,整个项目编译没有错误。使用f5运行时发生错误。这就是我得到的。 名称“calculationEntry”是一个函数,我认为函数在声明时已初始化。那么为什么会出现这种错误呢

        "use strict";
    __webpack_require__.r(__webpack_exports__);
    /* WEBPACK VAR INJECTION */(function(__react_refresh_utils__, __react_refresh_error_overlay__) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "calculationEntry", function() { return calculationEntry; });
                                                                                ^
    Exception has occurred: ReferenceError: Cannot access 'calculationEntry' before initialization
      at Module.calculationEntry (http://localhost:3000/static/js/main.chunk.js:5896:204)
        at Module.calculationEntry (http://localhost:3000/static/js/main.chunk.js:53960:169)
        at Object.registerExportsForReactRefresh (http://localhost:3000/static/js/vendors~main.chunk.js:995:38)
        at Module.<anonymous> (http://localhost:3000/static/js/main.chunk.js:54703:25)
        at Module../src/moduleNameSpace.js (http://localhost:3000/static/js/main.chunk.js:54775:30)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at fn (http://localhost:3000/static/js/bundle.js:151:20)
        at Module.<anonymous> (http://localhost:3000/static/js/main.chunk.js:5897:74)
        at Module../src/calculations/moduleCalc0.js (http://localhost:3000/static/js/main.chunk.js:6104:30)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at fn (http://localhost:3000/static/js/bundle.js:151:20)
        at Module.<anonymous> (http://localhost:3000/static/js/main.chunk.js:37915:84)
        at Module../src/components/Forecaster/index.js (http://localhost:3000/static/js/main.chunk.js:38243:30)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at fn (http://localhost:3000/static/js/bundle.js:151:20)
        at Module.<anonymous> (http://localhost:3000/static/js/main.chunk.js:47062:82)
        at Module../src/components/Root/Root.dev.js (http://localhost:3000/static/js/main.chunk.js:47396:30)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at fn (http://localhost:3000/static/js/bundle.js:151:20)
        at Object.<anonymous> (http://localhost:3000/static/js/main.chunk.js:47779:20)
        at Object../src/components/Root/index.js (http://localhost:3000/static/js/main.chunk.js:47855:30)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at fn (http://localhost:3000/static/js/bundle.js:151:20)
        at Module.<anonymous> (http://localhost:3000/static/js/main.chunk.js:51422:74)
        at Module../src/index.js (http://localhost:3000/static/js/main.chunk.js:51577:30)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at fn (http://localhost:3000/static/js/bundle.js:151:20)
        at Object.1 (http://localhost:3000/static/js/main.chunk.js:57861:18)
        at __webpack_require__ (http://localhost:3000/static/js/bundle.js:852:31)
        at checkDeferredModules (http://localhost:3000/static/js/bundle.js:46:23)
        at Array.webpackJsonpCallback [as push] (http://localhost:3000/static/js/bundle.js:33:19)
        at http://localhost:3000/static/js/main.chunk.js:1:79
“严格使用”;
__网页包需求(网页包导出);
/*WEBPACK VAR INJECTION*/(函数(\uuuu react\u refresh\u utils\uuuuu,\uuuuu react\u refresh\u error\u overlay\uuuuuuuuu){/*和谐导出(绑定)*/\uuu WEBPACK\u require\uuuuuuuuuu.d(\uuu WEBPACK\uu导出,“calculationEntry”,函数(){return calculationEntry;});
^
发生异常:ReferenceError:无法在初始化之前访问“calculationEntry”
在模块计算中心(http://localhost:3000/static/js/main.chunk.js:5896:204)
在模块计算中心(http://localhost:3000/static/js/main.chunk.js:53960:169)
在Object.registerexportsforeactrefresh(http://localhost:3000/static/js/vendors~main.chunk.js:995:38)
在模块上(http://localhost:3000/static/js/main.chunk.js:54703:25)
在Module../src/moduleNameSpace.js处(http://localhost:3000/static/js/main.chunk.js:54775:30)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在fn(http://localhost:3000/static/js/bundle.js:151:20)
在模块上(http://localhost:3000/static/js/main.chunk.js:5897:74)
在模块../src/calculations/moduleCalc0.js处(http://localhost:3000/static/js/main.chunk.js:6104:30)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在fn(http://localhost:3000/static/js/bundle.js:151:20)
在模块上(http://localhost:3000/static/js/main.chunk.js:37915:84)
在模块处../src/components/Forecaster/index.js(http://localhost:3000/static/js/main.chunk.js:38243:30)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在fn(http://localhost:3000/static/js/bundle.js:151:20)
在模块上(http://localhost:3000/static/js/main.chunk.js:47062:82)
位于Module../src/components/Root/Root.dev.js(http://localhost:3000/static/js/main.chunk.js:47396:30)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在fn(http://localhost:3000/static/js/bundle.js:151:20)
反对(http://localhost:3000/static/js/main.chunk.js:47779:20)
在Object../src/components/Root/index.js处(http://localhost:3000/static/js/main.chunk.js:47855:30)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在fn(http://localhost:3000/static/js/bundle.js:151:20)
在模块上(http://localhost:3000/static/js/main.chunk.js:51422:74)
在模块处../src/index.js(http://localhost:3000/static/js/main.chunk.js:51577:30)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在fn(http://localhost:3000/static/js/bundle.js:151:20)
目标1(http://localhost:3000/static/js/main.chunk.js:57861:18)
在需要的网页上(http://localhost:3000/static/js/bundle.js:852:31)
在checkDeferredModules上(http://localhost:3000/static/js/bundle.js:46:23)
在Array.webpackJsonpCallback[作为推送](http://localhost:3000/static/js/bundle.js:33:19)
在http://localhost:3000/static/js/main.chunk.js:1:79

我有一个模块执行所有导入并重新导出所有命名导出,我尝试阻止循环引用,我用calculationEntry函数移动了模块导入的位置,以查看它是否有影响。它没有。因此我需要一些帮助,了解如何使用此调试转储跟踪此TDZ异常问题。

问题的存在是因为函数被声明为箭头函数。因此,它被声明但未初始化。编译阶段将此未初始化的变量提升到时间死区,从而导致TDZ异常。更改函数声明
“函数计算入口(){…}”解决了这个问题。

函数声明的又一次胜利!:-)