超出最大调用堆栈大小错误

发布于 2024-11-08 18:38:45 字数 318 浏览 0 评论 0原文

我正在使用 Direct Web Remoting (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

暮年慕年 2024-11-15 18:38:45

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

这几乎总是因为递归函数的基本情况未得到满足。

查看堆栈

考虑这段代码...

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

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

Web Inspector

尽你所能看,调用堆栈会不断增长,直到达到极限:浏览器硬编码的堆栈大小或内存耗尽。

为了修复它,请确保您的递归函数具有能够满足的基本情况......

(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);
好久不见√ 2024-11-15 18:38:45

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

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

而不是:

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

这将我的 Chrome 选项卡冻结到了一个点,当页面变得无响应时,它甚至没有向我显示“等待/终止”对话框...

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...

待"谢繁草 2024-11-15 18:38:45

如果您不小心导入/嵌入同一个 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.

忆依然 2024-11-15 18:38:45

代码中的某处存在递归循环(即最终一次又一次调用自身直到堆栈已满的函数)。

其他浏览器要么有更大的堆栈(所以你会得到一个超时),要么因为某种原因吞掉错误(可能是放置不当的 try-catch)。

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

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.

不回头走下去 2024-11-15 18:38:45

检测堆栈溢出的问题是有时堆栈跟踪会展开,您将无法看到实际发生的情况。

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

点击性能选项卡,确保启用Javascript示例,您将得到类似这样的结果。

溢出的位置非常明显!如果您单击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

旧时浪漫 2024-11-15 18:38:45

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

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.

哎呦我呸! 2024-11-15 18:38:45

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

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

此处相同:

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

来自 Mozilla 文档

但要注意:以这种方式使用 apply 时,您可能会面临超出限制的风险
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]);
}
夢归不見 2024-11-15 18:38:45

就我而言,单击事件在子元素上传播。所以,我必须输入以下内容:

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>
夜巴黎 2024-11-15 18:38:45

就我而言,我有两个同名的变量!

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

蓝梦月影 2024-11-15 18:38:45

检查 Chrome 开发工具栏控制台中的错误详细信息,这将为您提供调用堆栈中的函数,并指导您找到导致错误的递归。

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.

影子的影子 2024-11-15 18:38:45

就我而言,我基本上忘记获取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}
画骨成沙 2024-11-15 18:38:45

发送输入元素而不是它们的值很可能会像 FK 提到的那样解决它

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

人间☆小暴躁 2024-11-15 18:38:45

如果您出于某种原因需要运行无限进程/递归,您可以在单独的线程中使用 webworker。
http://www.html5rocks.com/en/tutorials/workers/basics/< /a>

如果你想操作 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/

荒岛晴空 2024-11-15 18:38:45

这里几乎每个答案都表明这只能由无限循环引起。这不是真的,否则您可能会通过深度嵌套调用来过度运行堆栈(并不是说这是有效的,但它肯定在可能的范围内)。如果您可以控制 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

娇柔作态 2024-11-15 18:38:45

我们最近在我们正在开发的管理网站中添加了一个字段 - contact_type...很简单吧?好吧,如果你调用 select“type”并尝试通过 jquery ajax 调用发送它,它会失败,并在 jquery.js 中深深埋藏这个错误 不要这样做:

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

问题是 type:type - 我相信是我们将参数命名为“type”——有一个名为 type 的值变量不是问题。我们将其更改为:

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

并相应地重写了 some_function.php - 问题解决了。

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.

暗地喜欢 2024-11-15 18:38:45

就我而言,两个 jQuery 模式显示堆叠在一起。防止这种情况解决了我的问题。

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

心房敞 2024-11-15 18:38:45

检查您是否有一个调用自身的函数。例如

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()
  }
}
同尘 2024-11-15 18:38:45

对于我这个 TypeScript 初学者来说,这是 _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
    }
}
鸠魁 2024-11-15 18:38:45
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)];
    }
});

在上面的 data 函数中,我使用了相同的名称 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.

花开半夏魅人心 2024-11-15 18:38:45

该问题可能是由于递归调用没有任何终止条件所致。

就像我的例子一样,如果您看到下面的代码,我的 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.

︶ ̄淡然 2024-11-15 18:38:45

如果减少 1,则下面相同代码的两次调用都可以在我的计算机上的 Chrome 32 中运行,例如 17905 与 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);
慈悲佛祖 2024-11-15 18:38:45

我也遇到了类似的问题,这里是详细信息
上传徽标时,

<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]);
          }

我的代码是:控制台中的错误:

在此处输入图像描述

我通过删除 onclick="$('#filePhoto').click 解决了这个问题()" 来自 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.

找个人就嫁了吧 2024-11-15 18:38:45

我遇到了同样的问题
我已经通过删除在 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
    },
.....
若能看破又如何 2024-11-15 18:38:45

我的情况的问题是因为我的子路由与父路由具有相同的路径:

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' },
    ]
  }
];
淡忘如思 2024-11-15 18:38:45

当 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.

花海 2024-11-15 18:38:45

你可以在crome浏览器中找到你的递归函数,按ctrl+shift+j然后按source选项卡,这给你代码编译流程,你可以在代码中找到使用断点。

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.

苏璃陌 2024-11-15 18:38:45

我知道这个线程很旧,但我认为值得一提的是我发现这个问题的场景,这样它可以帮助其他人。

假设您有这样的嵌套元素:

<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");
});

您有两种选择来避免这种情况:

  • 将子级移动到父级的外部。
  • stopPropagation 函数应用于子元素。

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.
﹏雨一样淡蓝的深情 2024-11-15 18:38:45

我遇到这个错误是因为我有两个同名的 JS 函数

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

坚持沉默 2024-11-15 18:38:45

如果您正在使用谷歌地图,请检查传入 new google.maps.LatLng 的 lat lng 的格式是否正确。就我而言,它们被视为未定义。

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.

极度宠爱 2024-11-15 18:38:45

有时会因为转换数据类型而发生,例如您有一个被视为字符串的对象。

以nodejs或js客户端为例,socket.id不是字符串。要将其用作字符串,您必须在前面添加单词 String:

String(socket.id);

Sometimes happened because of convert data type , for example you have an object that you considered as string.

socket.id in nodejs either in js client as example, is not a string. to use it as string you have to add the word String before:

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