Namespace'已声明'当I'我只声明过一次

says that Namespace 'already been declared' when I've only declared it once

本文关键字:声明 一次 Namespace      更新时间:2023-09-26

这里是新手的问题,因为我刚刚开始用lime.js开发游戏,但我在下面收到了这个错误,我一辈子都不明白为什么这个错误说'moba.Bullet'已经声明了,因为我只提供过一次!

这是完整的错误:

Uncaught Error: Namespace "moba.Bullet" already declared. 
   goog.provide base.js:
   (anonymous function)

当查看base.js中错误的位置时,我得到的代码是:

goog.provide = function(name) {
  if (!COMPILED) {
    // Ensure that the same namespace isn't provided twice.
    // A goog.module/goog.provide maps a goog.require to a specific file
    if (goog.isProvided_(name)) {
      throw Error('Namespace "' + name + '" already declared.');
    }
  }

我只提供过一次命名空间!这让这件事更加令人困惑!!

要理解这个问题,查看我的文件结构将有所帮助。

我的lime.js游戏的文件夹结构看起来是这样的:

limejs >
  moba >
    moba.html
    moba.js
    bullet.js
  bin >
    lime.py
    projects
    external >
  closure
  box2D

我甚至运行了bin/lime.py更新,这样moba.js(主js文件)就能识别bullet.js!

现在我们来了解如何用goog.provide和goog.require.调用每个文件

moba.js >
  goog.provide('moba');
  goog.require('moba.Bullet');
bullet.js >
  goog.provide('moba.Bullet');
Pretty standard, right?!

我不知道从这里到哪里去。我试着通过命令行重新创建这个项目,但没有得到任何支持。所以请帮忙,谢谢你的帮助!

如果你看第一行,你会看到开始标记,然后第二行If(!COMPILED)有一个开始标记,第五行是If(goog.isProviderd_(name))和另一个开始标签,但代码末尾只有两个结束标记,我认为应该有第三个。

我也是一个新手,但在查看以下代码时,我注意到第一个if语句缺少结束标记:

goog.provide = function(name) {
  if (!COMPILED) {
    // Ensure that the same namespace isn't provided twice.
    // A goog.module/goog.provide maps a goog.require to a specific file
    if (goog.isProvided_(name)) {
      throw Error('Namespace "' + name + '" already declared.');
    }
  }

有时忘记关闭if语句会导致很多问题。希望这能有所帮助。