最大呼叫堆栈大小超过错误

发布于 2025-01-23 15:12:42 字数 304 浏览 7 评论 0原文

我正在使用直接的Web远程(DWR)JavaScript库文件,并且仅在Safari(桌面和iPad)中遇到

错误

超过最大呼叫堆栈大小。

此错误到底是什么意思,它是否完全停止处理?

另外,Safari浏览器的任何修复程序(实际上在iPad Safari上,它说

JS:执行超过超时

我假设是同一呼叫堆栈问题的超时时间)

I am using a Direct Web Remoting (DWR) JavaScript library file and am getting an error only in Safari (desktop and iPad)

It says

Maximum call stack size exceeded.

What exactly does this error mean and does it stop processing completely?

Also any fix for Safari browser (Actually on the iPad Safari, it says

JS:execution exceeded timeout

which I am assuming is the same call stack issue)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

听风念你 2025-01-30 15:12:42

这意味着您在代码中的某个地方调用了一个函数,该功能又调用另一个功能,依此类推,直到达到呼叫堆栈限制为止。

这几乎总是因为递归功能,其基本情况无法满足。

堆栈

考虑此代码...

(function a() {
    a();
})();

这是几次调用后的堆栈...

“

查看 请参阅呼叫堆栈成长,直到达到限制:浏览器硬编码的堆栈尺寸或内存耗尽。

为了修复它,请确保您的递归功能具有能够满足的基本案例...

(function a(x) {
    // The following condition 
    // is the base case.
    if ( ! x) {
        return;
    }
    a(--x);
})(10);

It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.

This is almost always because of a recursive function with a base case that isn't being met.

Viewing the stack

Consider this code...

(function a() {
    a();
})();

Here is the stack after a handful of calls...

Web Inspector

As you can see, the call stack grows until it hits a limit: the browser hardcoded stack size or memory exhaustion.

In order to fix it, ensure that your recursive function has a base case which is able to be met...

(function a(x) {
    // The following condition 
    // is the base case.
    if ( ! x) {
        return;
    }
    a(--x);
})(10);
谁的年少不轻狂 2025-01-30 15:12:42

就我而言,我是在发送输入元素而不是它们的值:

$.post( '',{ registerName: $('#registerName') } )

而不是:

$.post( '',{ registerName: $('#registerName').val() } )

这将我的铬片冻结到一个点,甚至没有向我显示“ wait/kill”对话框,因为该页面变得无反应...

In my case, I was sending input elements instead of their values:

$.post( '',{ registerName: $('#registerName') } )

Instead of:

$.post( '',{ registerName: $('#registerName').val() } )

This froze my Chrome tab to a point it didn't even show me the 'Wait/Kill' dialog for when the page became unresponsive...

自由如风 2025-01-30 15:12:42

如果您两次意外导入/嵌入相同的JavaScript文件,有时可以得到此功能,值得在检查员的资源选项卡中检查。

You can sometimes get this if you accidentally import/embed the same JavaScript file twice, worth checking in your resources tab of the inspector.

草莓味的萝莉 2025-01-30 15:12:42

代码中某个地方的某个地方有一个递归循环(即最终一次又一次地调用自己的函数,直到堆栈已满)。

其他浏览器要么具有较大的堆栈(因此您会获得超时),要么出于某种原因吞咽错误(也许是一个不好的trycatch)。

发生错误时,请使用调试器检查呼叫堆栈。

There is a recursive loop somewhere in your code (i.e. a function that eventually calls itself again and again until the stack is full).

Other browsers either have bigger stacks (so you get a timeout instead) or they swallow the error for some reason (maybe a badly placed try-catch).

Use the debugger to check the call stack when the error happens.

病毒体 2025-01-30 15:12:42

检测Stackoverflows的问题有时是堆栈跟踪会放松,您将无法看到实际发生的事情。

我发现Chrome的一些更新的调试工具对此很有用。

点击性能选项卡,请确保已启用JavaScript Samples已启用,您将获得类似的东西。

很明显,溢出在这里!如果单击ExtendObject,您将可以实际看到代码中的确切行号。

您还可以看到可能有帮助或红鲱鱼的时间。


如果您实际上找不到问题是在您认为问题所在的地方放置大量console.log语句。上面的前一步可以帮助您解决这个问题。

在Chrome中,如果您反复输出相同的数据,它将像这样显示问题更清晰的位置显示。在这种情况下,堆栈在最终崩溃之前击中了7152帧:

”在此处输入图像描述”

The problem with detecting stackoverflows is sometimes the stack trace will unwind and you won't be able to see what's actually going on.

I've found some of Chrome's newer debugging tools useful for this.

Hit the Performance tab, make sure Javascript samples are enabled and you'll get something like this.

It's pretty obvious where the overflow is here! If you click on extendObject you'll be able to actually see the exact line number in the code.

enter image description here

You can also see timings which may or may not be helpful or a red herring.

enter image description here


Another useful trick if you can't actually find the problem is to put lots of console.log statements where you think the problem is. The previous step above can help you with this.

In Chrome if you repeatedly output identical data it will display it like this showing where the problem is more clearly. In this instance the stack hit 7152 frames before it finally crashed:

enter image description here

ま柒月 2025-01-30 15:12:42

就我而言,我使用以下内容将大字节数组转换为字符串:

String.fromCharCode.apply(null, new Uint16Array(bytes))

bytes包含数百万个条目,这太大了,无法放在堆栈上。

In my case, I was converting a large byte array into a string using the following:

String.fromCharCode.apply(null, new Uint16Array(bytes))

bytes contained several million entries, which is too big to fit on the stack.

不寐倦长更 2025-01-30 15:12:42

这也可能导致最大调用堆栈大小超过错误:

var items = [];
[].push.apply(items, new Array(1000000)); //Bad

在此处相同:

items.push(...new Array(1000000)); //Bad

来自 mozilla docs

但要当心:在使用这种方式时,您有可能超出
JavaScript引擎的参数长度限制。后果
应用过多的论点应用功能(想想超过数十个
数以千计的论点)各不相同(JavaScriptCore有
硬编码的参数限制为65536),因为限制(实际上甚至是
任何过多的堆栈行为的性质)未指定。
一些发动机会引起例外。更有用,其他人会
任意限制实际传递给该参数的数量
应用功能。为了说明后一种情况:如果这样的引擎
有四个论点的限制(实际限制当然是
明显更高),好像争论5、6、2、3有
被通过用于上面的示例,而不是完整的
数组。

所以尝试:

var items = [];
var newItems = new Array(1000000);
for(var i = 0; i < newItems.length; i++){
  items.push(newItems[i]);
}

This can also cause a Maximum call stack size exceeded error:

var items = [];
[].push.apply(items, new Array(1000000)); //Bad

Same here:

items.push(...new Array(1000000)); //Bad

From the Mozilla Docs:

But beware: in using apply this way, you run the risk of exceeding the
JavaScript engine's argument length limit. The consequences of
applying a function with too many arguments (think more than tens of
thousands of arguments) vary across engines (JavaScriptCore has
hard-coded argument limit of 65536), because the limit (indeed even
the nature of any excessively-large-stack behavior) is unspecified.
Some engines will throw an exception. More perniciously, others will
arbitrarily limit the number of arguments actually passed to the
applied function. To illustrate this latter case: if such an engine
had a limit of four arguments (actual limits are of course
significantly higher), it would be as if the arguments 5, 6, 2, 3 had
been passed to apply in the examples above, rather than the full
array.

So try:

var items = [];
var newItems = new Array(1000000);
for(var i = 0; i < newItems.length; i++){
  items.push(newItems[i]);
}
淡写薰衣草的香 2025-01-30 15:12:42

就我而言,点击事件正在传播子元素。因此,我不得不说以下内容:

e.stoppropagation()

在单击事件上:

 $(document).on("click", ".remove-discount-button", function (e) {
           e.stopPropagation();
           //some code
        });
 $(document).on("click", ".current-code", function () {
     $('.remove-discount-button').trigger("click");
 });

这是HTML代码:

 <div class="current-code">                                      
      <input type="submit" name="removediscountcouponcode" value="
title="Remove" class="remove-discount-button">
   </div>

In my case, click event was propagating on child element. So, I had to put the following:

e.stopPropagation()

on click event:

 $(document).on("click", ".remove-discount-button", function (e) {
           e.stopPropagation();
           //some code
        });
 $(document).on("click", ".current-code", function () {
     $('.remove-discount-button').trigger("click");
 });

Here is the html code:

 <div class="current-code">                                      
      <input type="submit" name="removediscountcouponcode" value="
title="Remove" class="remove-discount-button">
   </div>
好倦 2025-01-30 15:12:42

就我而言,这是我有2个具有相同名称的变量!

In my case, it was that I have 2 variables with the same name!

抹茶夏天i‖ 2025-01-30 15:12:42

检查Chrome Dev工具栏控制台中的错误详细信息,这将为您提供呼叫堆栈中的功能,并引导您朝着导致错误的递归。

Check the error details in the Chrome dev toolbar console, this will give you the functions in the call stack, and guide you towards the recursion that's causing the error.

小嗲 2025-01-30 15:12:42

就我而言,我基本上忘记了Inputvalue

错误

let name=document.getElementById('name');
param={"name":name}

正确

let name=document.getElementById('name').value;
param={"name":name}

In my case, I basically forget to get the value of input.

Wrong

let name=document.getElementById('name');
param={"name":name}

Correct

let name=document.getElementById('name').value;
param={"name":name}
用心笑 2025-01-30 15:12:42

发送输入元素而不是其值很可能像FK一样解决它

Sending input elements instead of their values will most likely resolve it like FK mentioned

七七 2025-01-30 15:12:42

如果由于某种原因需要运行无限的过程/递归,则可以在单独的线程中使用网络工作者。

如果要操纵dom元素并重新绘制,请使用动画
http://creativejs.com/resources/requestanimationframe/

If you need a infinite process/recursion running for some reason, you can use a webworker in a seperate thread.
http://www.html5rocks.com/en/tutorials/workers/basics/

if you want to manipulate dom elements and redraw, use animation
http://creativejs.com/resources/requestanimationframe/

锦欢 2025-01-30 15:12:42

这里几乎每个答案都指出,这只能由无限循环引起。事实并非如此,否则您可以通过深度嵌套的呼叫过度运行堆栈(并不是说这是有效的,但这肯定是可能的领域)。如果您可以控制JavaScript VM,则可以调整堆栈尺寸。例如:

node -stack-size = 2000

另请参见:我如何增加node.js中的最大呼叫堆栈大小

Nearly every answer here states that this can only be caused by an infinite loop. That's not true, you could otherwise over-run the stack through deeply nested calls (not to say that's efficient, but it's certainly in the realm of possible). If you have control of your JavaScript VM, you can adjust the stack size. For example:

node --stack-size=2000

See also: How can I increase the maximum call stack size in Node.js

-柠檬树下少年和吉他 2025-01-30 15:12:42

最近,我们在正在研究的管理站点中添加了一个字段-Contact_Type ...容易吧?好吧,如果您称选择“类型”并尝试通过jQuery ajax调用来发送它,则该错误埋在jquery.js中不执行此操作:

$.ajax({
    dataType: "json",
    type: "POST",
    url: "/some_function.php",
    data: { contact_uid:contact_uid, type:type }
});

问题是那种类型:类型 - 我相信这是我们命名参数“类型” - 具有命名类型的值变量不是问题。我们将其更改为:

$.ajax({
    dataType: "json",
    type: "POST",
    url: "/some_function.php",
    data: { contact_uid:contact_uid, contact_type:type }
});

相应地解决问题 - 解决问题。

We recently added a field to an admin site we are working on - contact_type... easy right? Well, if you call the select "type" and try to send that through a jquery ajax call it fails with this error buried deep in jquery.js Don't do this:

$.ajax({
    dataType: "json",
    type: "POST",
    url: "/some_function.php",
    data: { contact_uid:contact_uid, type:type }
});

The problem is that type:type - I believe it is us naming the argument "type" - having a value variable named type isn't the problem. We changed this to:

$.ajax({
    dataType: "json",
    type: "POST",
    url: "/some_function.php",
    data: { contact_uid:contact_uid, contact_type:type }
});

And rewrote some_function.php accordingly - problem solved.

美人骨 2025-01-30 15:12:42

就我而言,两种jQuery模式彼此堆叠。防止这解决了我的问题。

In my case, two jQuery modals were showing stacked on top of each other. Preventing that solved my problem.

何以畏孤独 2025-01-30 15:12:42

检查您是否具有调用自己的函数。例如

export default class DateUtils {
  static now = (): Date => {
    return DateUtils.now()
  }
}

Check if you have a function that calls itself. For example

export default class DateUtils {
  static now = (): Date => {
    return DateUtils.now()
  }
}
独木成林 2025-01-30 15:12:42

对我来说,作为打字稿的初学者,这是 _var1 的getter和setter中的问题。

class Point2{
    
    constructor(private _var1?: number, private y?: number){}

    set var1(num: number){
        this._var1 = num  // problem was here, it was this.var1 = num
    }
    get var1(){
        return this._var1 // this was return this.var1
    }
}

For me as a beginner in TypeScript, it was a problem in the getter and the setter of _var1.

class Point2{
    
    constructor(private _var1?: number, private y?: number){}

    set var1(num: number){
        this._var1 = num  // problem was here, it was this.var1 = num
    }
    get var1(){
        return this._var1 // this was return this.var1
    }
}
哭了丶谁疼 2025-01-30 15:12:42
dtTable.dataTable({
    sDom: "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
    "processing": true,
    "serverSide": true,
    "order": [[6, "desc"]],
    "columnDefs": [
        {className: "text-right", "targets": [2, 3, 4, 5]}
    ],
    "ajax": {
        "url": "/dt",
        "data": function (d) {
            d.loanRef = loanRef;
        }
    },
    "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        var editButton = '';
        // The number of columns to display in the datatable
        var cols = 8;
        // Th row element's ID
        var id = aData[(cols - 1)];
    }
});

在上面的数据函数中,我使用了相同的名称d.loanref = loanref,但没有创建一个变量loanref因此递归声明自己。

解决方案:声明LoanRef变量或更高的内容,请使用与d.loanref上使用的名称不同的名称。

dtTable.dataTable({
    sDom: "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
    "processing": true,
    "serverSide": true,
    "order": [[6, "desc"]],
    "columnDefs": [
        {className: "text-right", "targets": [2, 3, 4, 5]}
    ],
    "ajax": {
        "url": "/dt",
        "data": function (d) {
            d.loanRef = loanRef;
        }
    },
    "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        var editButton = '';
        // The number of columns to display in the datatable
        var cols = 8;
        // Th row element's ID
        var id = aData[(cols - 1)];
    }
});

In the data function above, I used the same name d.loanRef = loanRef but had not created a variable loanRef therefore recursively declaring itself.

Solution: Declare a loanRef variable or better still, use a different name from the one used on d.loanRef.

无敌元气妹 2025-01-30 15:12:42

问题可能是由于递归电话没有任何基本条件以终止。

就像我的情况下一样,如果您看到以下代码,我的API调用方法的名称相同,并且我用来执行API调用操作的方法。

const getData = async () => {
try {
  const response = await getData(props.convID);
  console.log("response", response);
 } catch (err) {
  console.log("****Error****", err);
}
};

因此,基本上,解决方案是删除此递归调用

The issue might be because of recursive calls without any base condition for it to terminate.

Like in my case, if you see the below code, I had the same name for the API call method and the method which I used to perform operations post that API call.

const getData = async () => {
try {
  const response = await getData(props.convID);
  console.log("response", response);
 } catch (err) {
  console.log("****Error****", err);
}
};

So, basically, the solution is to remove this recursive call.

圈圈圆圆圈圈 2025-01-30 15:12:42

如果在我的计算机上的Chrome 32中通过1个工作减少了以下相同代码的两种调用,例如17905 vs 17904。如果运行,则会产生错误“ rangeerror:最大呼叫堆栈大小超过”。似乎不是硬编码,而是取决于计算机的硬件。看来,如果作为函数调用,则自我强加的限制比作为方法调用的限制高,即当调用作为函数时,该特定代码使用的内存较少。

称为一种方法:

var ninja = {
    chirp: function(n) {
        return n > 1 ? ninja.chirp(n-1) + "-chirp" : "chirp";
    }
};

ninja.chirp(17905);

调用为函数:

function chirp(n) {
    return n > 1 ? chirp( n - 1 ) + "-chirp" : "chirp";
}

chirp(20889);

Both invocations of the identical code below if decreased by 1 work in Chrome 32 on my computer e.g. 17905 vs 17904. If run as is they will produce the error "RangeError: Maximum call stack size exceeded". It appears to be this limit is not hardcoded but dependant on the hardware of your machine. It does appear that if invoked as a function this self-imposed limit is higher than if invoked as a method i.e. this particular code uses less memory when invoked as a function.

Invoked as a method:

var ninja = {
    chirp: function(n) {
        return n > 1 ? ninja.chirp(n-1) + "-chirp" : "chirp";
    }
};

ninja.chirp(17905);

Invoked as a function:

function chirp(n) {
    return n > 1 ? chirp( n - 1 ) + "-chirp" : "chirp";
}

chirp(20889);
究竟谁懂我的在乎 2025-01-30 15:12:42

我也面临着类似的问题,这是细节
使用下拉徽标上传徽标上传时上传框

<div>
      <div class="uploader greyLogoBox" id="uploader" flex="64" onclick="$('#filePhoto').click()">
        <img id="imageBox" src="{{ $ctrl.companyLogoUrl }}" alt=""/>
        <input type="file" name="userprofile_picture"  id="filePhoto" ngf-select="$ctrl.createUploadLogoRequest()"/>
        <md-icon ng-if="!$ctrl.isLogoPresent" class="upload-icon" md-font-set="material-icons">cloud_upload</md-icon>
        <div ng-if="!$ctrl.isLogoPresent" class="text">Drag and drop a file here, or click to upload</div>
      </div>
      <script type="text/javascript">
          var imageLoader = document.getElementById('filePhoto');
          imageLoader.addEventListener('change', handleImage, false);

          function handleImage(e) {
              var reader = new FileReader();
              reader.onload = function (event) {

                  $('.uploader img').attr('src',event.target.result);
              }
              reader.readAsDataURL(e.target.files[0]);
          }
      </script>
      </div>

CSS.CSS

.uploader {
  position:relative;
  overflow:hidden;
  height:100px;
  max-width: 75%;
  margin: auto;
  text-align: center;

  img{
    max-width: 464px;
    max-height: 100px;
    z-index:1;
    border:none;
  }

  .drag-drop-zone {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.12);
    padding: 32px;
  }
}

.uploader img{
  max-width: 464px;
  max-height: 100px;
  z-index:1;
  border:none;
}



.greyLogoBox {
  width: 100%;
  background: #EBEBEB;
  border: 1px solid #D7D7D7;
  text-align: center;
  height: 100px;
  padding-top: 22px;
  box-sizing: border-box;
}


#filePhoto{
  position:absolute;
  width:464px;
  height:100px;
  left:0;
  top:0;
  z-index:2;
  opacity:0;
  cursor:pointer;
}

校正之前,我的代码是:

function handleImage(e) {
              var reader = new FileReader();
              reader.onload = function (event) {
                  onclick="$('#filePhoto').click()"
                  $('.uploader img').attr('src',event.target.result);
              }
              reader.readAsDataURL(e.target.files[0]);
          }

console中的错误:

我通过删除onclick =“ $(#filephoto')。 ()“来自DIV标签。

I also faced similar issue here is the details
when uploading logo using dropdown logo upload box

<div>
      <div class="uploader greyLogoBox" id="uploader" flex="64" onclick="$('#filePhoto').click()">
        <img id="imageBox" src="{{ $ctrl.companyLogoUrl }}" alt=""/>
        <input type="file" name="userprofile_picture"  id="filePhoto" ngf-select="$ctrl.createUploadLogoRequest()"/>
        <md-icon ng-if="!$ctrl.isLogoPresent" class="upload-icon" md-font-set="material-icons">cloud_upload</md-icon>
        <div ng-if="!$ctrl.isLogoPresent" class="text">Drag and drop a file here, or click to upload</div>
      </div>
      <script type="text/javascript">
          var imageLoader = document.getElementById('filePhoto');
          imageLoader.addEventListener('change', handleImage, false);

          function handleImage(e) {
              var reader = new FileReader();
              reader.onload = function (event) {

                  $('.uploader img').attr('src',event.target.result);
              }
              reader.readAsDataURL(e.target.files[0]);
          }
      </script>
      </div>

CSS.css

.uploader {
  position:relative;
  overflow:hidden;
  height:100px;
  max-width: 75%;
  margin: auto;
  text-align: center;

  img{
    max-width: 464px;
    max-height: 100px;
    z-index:1;
    border:none;
  }

  .drag-drop-zone {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.12);
    padding: 32px;
  }
}

.uploader img{
  max-width: 464px;
  max-height: 100px;
  z-index:1;
  border:none;
}



.greyLogoBox {
  width: 100%;
  background: #EBEBEB;
  border: 1px solid #D7D7D7;
  text-align: center;
  height: 100px;
  padding-top: 22px;
  box-sizing: border-box;
}


#filePhoto{
  position:absolute;
  width:464px;
  height:100px;
  left:0;
  top:0;
  z-index:2;
  opacity:0;
  cursor:pointer;
}

before correction my code was :

function handleImage(e) {
              var reader = new FileReader();
              reader.onload = function (event) {
                  onclick="$('#filePhoto').click()"
                  $('.uploader img').attr('src',event.target.result);
              }
              reader.readAsDataURL(e.target.files[0]);
          }

The error in console:

enter image description here

I solved it by removing onclick="$('#filePhoto').click()" from div tag.

豆芽 2025-01-30 15:12:42

我面临同一问题
我通过删除在Ajax两次使用的字段名称来解决它
例如

    jQuery.ajax({
    url : '/search-result',
    data : {
      searchField : searchField,
      searchFieldValue : searchField,
      nid    :  nid,
      indexName : indexName,
      indexType : indexType
    },
.....

I was facing same issue
I have resolved it by removing a field name which was used twice on ajax
e.g

    jQuery.ajax({
    url : '/search-result',
    data : {
      searchField : searchField,
      searchFieldValue : searchField,
      nid    :  nid,
      indexName : indexName,
      indexType : indexType
    },
.....
无人问我粥可暖 2025-01-30 15:12:42

在我的情况下,问题是因为我有孩子路线与父母相同的路线:

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    children: [
      { path: '', redirectTo: 'home', pathMatch: 'prefix' },
      { path: 'home', loadChildren: './home.module#HomeModule' },
    ]
  }
];

所以我不得不删除孩子的路线

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    children: [
      { path: 'home', loadChildren: './home.module#HomeModule' },
    ]
  }
];

The issue in my case is because I have children route with same path with the parent :

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    children: [
      { path: '', redirectTo: 'home', pathMatch: 'prefix' },
      { path: 'home', loadChildren: './home.module#HomeModule' },
    ]
  }
];

So I had to remove the line of the children route

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
    children: [
      { path: 'home', loadChildren: './home.module#HomeModule' },
    ]
  }
];
巨坚强 2025-01-30 15:12:42

当MongoDB数据库的模式和我们创建的模型不匹配时,我在Express/Nodejs应用程序中遇到了此错误。

I got this error in express/nodejs app, when the schema of MongoDB database and the models which we have created don't match.

坠似风落 2025-01-30 15:12:42

就我而言,在app.module.ts中,我遇到了此错误,因为我在Imports和entryComponents中声明了组件。

Example:

import { MyComponent } from '....';

@NgModule({
  declarations: [
    MyComponent 
  ],
  imports: [
    MyComponent  -- > remove this from here!!!!
  ],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: [MyComponent]
})
export class AppModule { }

In my case, in app.module.ts, I got this error because I declared the component in imports and entryComponents.

Example:

import { MyComponent } from '....';

@NgModule({
  declarations: [
    MyComponent 
  ],
  imports: [
    MyComponent  -- > remove this from here!!!!
  ],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: [MyComponent]
})
export class AppModule { }
鹊巢 2025-01-30 15:12:42

您可以在Crome浏览器中找到递归功能,按Ctrl+Shift+J,然后在源选项卡中找到代码汇编流,您可以在代码中使用Break Point找到。

you can find your recursive function in crome browser,press ctrl+shift+j and then source tab, which gives you code compilation flow and you can find using break point in code.

乖不如嘢 2025-01-30 15:12:42

我知道这个线程很旧,但是我认为值得一提的是我发现这个问题的情况,以便可以帮助他人。

假设您已经嵌套了这样的元素:

<a href="#" id="profile-avatar-picker">
    <span class="fa fa-camera fa-2x"></span>
    <input id="avatar-file" name="avatar-file" type="file" style="display: none;" />
</a>

您无法操纵父母事件中的子元素事件,因为它会传播自身,进行递归呼叫,直到抛出例外。

因此,此代码将失败:

$('#profile-avatar-picker').on('click', (e) => {
    e.preventDefault();

    $('#profilePictureFile').trigger("click");
});

您有两个选择可以避免这种情况:

I know this thread is old, but i think it's worth mentioning the scenario i found this problem so it can help others.

Suppose you have nested elements like this:

<a href="#" id="profile-avatar-picker">
    <span class="fa fa-camera fa-2x"></span>
    <input id="avatar-file" name="avatar-file" type="file" style="display: none;" />
</a>

You cannot manipulate the child element events inside the event of its parent because it propagates to itself, making recursive calls until the exception is throwed.

So this code will fail:

$('#profile-avatar-picker').on('click', (e) => {
    e.preventDefault();

    $('#profilePictureFile').trigger("click");
});

You have two options to avoid this:

  • Move the child to the outside of the parent.
  • Apply stopPropagation function to the child element.
鹿童谣 2025-01-30 15:12:42

我有这个错误,因为我有两个JS功能,同名

I had this error because I had two JS Functions with the same name

戴着白色围巾的女孩 2025-01-30 15:12:42

如果您正在使用Google Maps,请检查LAT LNG是否被传递到新的Google.maps.latlng是一种适当的格式。就我而言,他们被不确定。

If you are working with google maps, then check if the lat lng are being passed into new google.maps.LatLng are of a proper format. In my case they were being passed as undefined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文