未捕获的类型错误:无法调用 null 的方法"shift"



我只在Chrome中收到此消息。火狐工作得很好。我一直在调试,试图找出此错误发生在什么时候,似乎无法确定它。确切的消息是,"未捕获的类型错误:无法调用 null 的方法'shift'"来自 all.js:57。

另外,我会指出其他一些可以帮助您帮助我的事情:

  • 我正在将 SDK 加载为 requirejs 模块。我也尝试以"正常方式"加载它,但结果是一样的。
  • 它不会在本地发生,只会在我们的暂存服务器上发生。这让我认为它在 SDK 加载期间与延迟有关。
  • 它只发生在Chrome中。Firefox 和 Safari 一样有效。Safari 中唯一的区别是我看到一个类似的错误,指出这是一个类型问题。那里的消息是"'null'不是对象(评估'queue.shift')"@ debug.js:2712,但它不会破坏应用程序。

这里的任何帮助和/或见解都会很棒。

重写调用 SDK 脚本对我有帮助。它需要按照Facebook上的解释来调用。

首先,我尝试仅使用 id='fasebook-jssdk' 将脚本附加到 head 元素,但方法"shift"发生了错误。然后我按照Facebook的建议重写了它,没有FB.init()。但是错误一直发生,直到我添加FB.init()调用。现在它工作正常。

为了解决它,我找到了"all.js"文件的调试版本,其中我发现错误发生在以下代码中:

function flush() {
  if (!queue) {
    return;
  }
  var fn;
  while (fn = queue.shift()) {
    fn();
  }
  queue = null;
}

其中队列是一个函数数组。我不知道原因,但现在,当脚本顺利时,我真的不需要。也许比我更谨慎的人会发现。

我也有类似的问题。这为我解决了。这些是症状:

  1. 本地主机没有问题
  2. 在服务器 (Amazon S3) 上,偶尔会出现"未捕获的类型错误:无法调用 null 的方法'shift'"

溶液:

我搞砸了Facebook SDK的包含顺序和fbAsyncInit的处理程序。在包含用于处理 SDK 加载的脚本后,应包含 SDK。否则,SDK 可能会在注册其 load 事件的处理程序之前加载。

<script src="Your script with fbAsyncInit here"> </script>
   <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=200817623450198";
      fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
    </script>
  <div id="fb-root"></div>
  </body>

抱歉,我可以提供帮助很多,但我有同样的问题,可能有助于解决问题。

加载 JS 像这样:

<script src='//connect.facebook.net/en_US/all.js'></script> 

"它不是在本地发生的,只发生在我们的登台服务器上。这让我 认为它在 SDK 加载期间有延迟。

我倾向于同意。该错误似乎只是偶尔发生。此外,我偶尔会收到CURLOPT_IPRESOLVE未定义的错误。似乎这一切都与连接有关。

这些Facebook说明解释了调用SDK的不同方法,这对我有用。我还没有测试过,但我认为频道文件会让你在本地测试这个,这超级甜蜜。

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID from the App Dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });
    // Additional initialization code such as adding Event Listeners goes here
  };
  // Load the SDK's source Asynchronously
  // Note that the debug version is being actively developed and might 
  // contain some type checks that are overly strict. 
  // Please report such bugs using the bugs tool.
  (function(d, debug){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
     ref.parentNode.insertBefore(js, ref);
   }(document, /*debug*/ false));
</script>

最新更新