dart - Dart:提供服务时,酒吧建立无效

标签 dart dart-pub

我正在尝试使用“pub build”构建我的WebGL dart应用程序。
我能够顺利运行“发布服务”,但是“发布版本”却给我2错误:

Directive not allowed here
part of MyProject
^^^^^^^^^^^^^^^^
Could not find main [I think this happends because of unfinished compile]

我只使用browser:any作为依赖项。
为什么会这样呢?

非常感谢你!

编辑:
我的pubspec.yaml

name: LD29
description: My LD29 game
author: snip
homepage: snip
dependencies:
    browser: any

包括:



library LD29;

import 'dart:html';
import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'dart:web_gl';

part 'Scene.dart';
part 'MainScene.dart';
part 'Entities.dart';

part 'Quadgrid.dart';
part 'Vecd.dart';
part 'Quad.dart';
part 'TexQuad.dart';
part 'ShaderProgram.dart';
part 'ShaderSource.dart';
part 'TextureGL.dart';
part 'FontRendering.dart';

有问题的“一部分”

part of LD29;

class Quadgrid {

  const static int size = 20;
  const MAX_GRID_W = DISPLAY_WIDTH / size;
  const MAX_GRID_H = DISPLAY_HEIGHT / size;

  ...
}

看来与我的其他文件没有什么不同。

最佳答案

好的,几个月后再回来,我又调试了这个问题。对于我的应用程序,我们将main()方法移到了与顶部带有“library coUclient”命令的文件不同的文件。这意味着“发布构建”将失败:

master@dellaptop ~/Dropbox/Dart/coUclient $ pub build
Loading source assets... 
Building coUclient... 
[Info from Dart2JS]:
Compiling coUclient|web/dart/engine/initialize.dart...
[Error from Dart2JS]:
web/dart/engine/initialize.dart:1:1:
Directive not allowed here.
part of coUclient;
^^^^^^^^^^^^^^^^^^
[Warning from Dart2JS]:
web/dart/engine/initialize.dart:11:5:
Cannot resolve 'localStorage'.
        if(localStorage["interface"] == null || localStorage["interface"] == "desktop")
    ^^^^^^^^^^^^

我不知道为什么以前没有看到它,但是让我惊讶的是,我看到它开始使用initalize.dart进行编译,而我发现那是其中包含main()的文件。然后,我将main()方法移回main.dart(在顶部具有“library coUclient”命令)并重新运行pub build。这次成功了,因为它开始了:
Loading source assets... 
Building coUclient... 
[Info from Dart2JS]:
Compiling coUclient|web/main.dart...
[Dart2JS on coUclient|web/main.dart]:

一切顺利。

故事的寓意是,确保您的main()与“library”命令位于同一文件中,并且不应发生“此处不允许指令”问题。

关于dart - Dart:提供服务时,酒吧建立无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328735/

相关文章:

flutter - 2个 future 一股波动

Flutter List<dynamic> 不是 FutureOr<List<Donation>> 类型的子类型

Flutter:如何弹出多个参数

firebase - 在 flutter 中过滤来自 firebase 的数据

dart - Dart Pub uploader 部分登录格式

flutter - 如何序列化和反序列化2D矩阵?

dart - 如何使用新的测试包调试浏览器测试

regex - 正则表达式使用Dart lang

dart - 谁应该被认为是 pubspec.yaml 中的作者?