I am trying to build my WebGL dart application with "pub build".
I am able to run "pub serve" without problems, but "pub build" gives me 2 erros:
Directive not allowed here
part of MyProject
^^^^^^^^^^^^^^^^
Could not find main [I think this happends because of unfinished compile]
I only use browser:any as dependency.
Why could this be?
Thank you very much!
EDIT:
My pubspec.yaml
name: LD29
description: My LD29 game
author: snip
homepage: snip
dependencies:
browser: any
The includes:
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';
The problematic "part of"
part of LD29;
class Quadgrid {
const static int size = 20;
const MAX_GRID_W = DISPLAY_WIDTH / size;
const MAX_GRID_H = DISPLAY_HEIGHT / size;
...
}
It seems no diffrent from my other files.
OK, after coming back to it a few months later, I gave debugging this problem another go. For my application, we moved the main() method to a different file than the one that had the 'library coUclient' command at the top. This meant that 'pub build' would fail:
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")
^^^^^^^^^^^^
I don't know why I didn't see it before, but what tipped me off was that I saw it was starting the compile with initalize.dart and it occurred to me that that was the file that had main() in it. I then moved the main() method back into main.dart (which has the 'library coUclient' command at the top) and re-ran pub build. This time it succeeded because it started:
Loading source assets...
Building coUclient...
[Info from Dart2JS]:
Compiling coUclient|web/main.dart...
[Dart2JS on coUclient|web/main.dart]:
and all went well.
Moral of the story is, make sure your main() is in the same file as your 'library ' command and the "Directive not allowed here" problem shouldn't happen.
Related
I want to create a Builder that would create Env class on the fly. That class should be available for import anywhere in my project. It is as container for environment constants defined in build.yml
Builder itself works fine, it generates desired output, however when I run
pub run build_runner build
build fails with following message
[SEVERE] build_web_compilers:entrypoint on web/main.dart: Unable to
find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a
dev_dependency needs to move to a real dependency), or a build failure
(if importing a generated file).
Please check the following imports:
import
'../.dart_tool/build/generated/buildertest/lib/environment.g.dart';
from buildertest|web/main.dart at 2:1
[INFO] Running build completed, took 4.1s [INFO] Caching finalized
dependency graph completed, took 450ms [SEVERE] Failed after 4.6s
import by itself is ok, as it works fine when I run following snippet
import '../.dart_tool/build/generated/buildertest/lib/environment.g.dart';
void main() {
print("Name:${Environment.name}");
print("Endpoint:${Environment.endpoint}");
}
with
dart web/main.dart
What should be done to make this import valid??
Here is build.yaml
targets:
$default:
builders:
angular_components|scss_builder:
enabled: True
env|builder:
options:
name: "default"
endpoint: "http://example.org"
enabled: true
builders:
env|builder:
import: "env/EnvBuilder.dart"
builder_factories: ["builderFactory"]
is_optional: false
build_extensions:
"$lib$": ["environment.g.dart"]
auto_apply: root_package
runs_before: ["build_test:test_bootstrap","build_modules:module_library","build_modules:dartdevc","build_web_compilers:ddc","build_modules:vm","build_modules:dart2js","build_web_compilers:entrypoint"]
I try to run in VSCode a simple dart program with
import 'dart:html';
clause.
import 'dart:html';
// import 'package:html/dom.dart';
// import 'package:html/dom_parsing.dart';
// import 'package:html/parser.dart';
void main() async{
var myTable = new TableElement()
..setAttribute('border','1');
// ..setAttribute(name, value);
...
In Run mode (I use VSCode extension "Code Runner 0.9.9") and in Debug appeared the same error:
Error: Not found: 'dart:html'
import 'dart:html';
I have installed Dart SDK 2.3.1 at Windows10 and not installed Flutter at all.
PATH pointed to Dart SDK bin directory
PATH =D:\Dart\dart-sdk\bin;
*) At project directory I try to add additional directive at pubspec.yaml
dependencies:
----
name: main
description: Test App sample22
dependencies:
html:
---
After "pub get" command I'll see that html present but error still persist.
pub get
Resolving dependencies...
+ charcode 1.1.2
+ csslib 0.16.0
+ html 0.14.0+2
+ path 1.6.2
+ source_span 1.5.5
+ term_glyph 1.1.0
Changed 6 dependencies!
*) My next step was to import html parts via "package:html/" (marked as comments in code sample). It is not helped and required class TableElement still unrecognizable.
"main.dart:8:19: Error: Method not found: 'TableElement'."
*) I try to change "launch.json" string from
default
"program": "bin/main.dart",
to
"program": "D:/Dart/WRK03t/main.dart",
And rename my code file to "main.dart"
*) Also I try to remove Dart extension from VSCode, restart PC and install it again. it's not helped.
But let me say that when I compile main.dart to js
"dart2js -m -o tst.js main.dart"
Resulted tst.js run correctly within the html page.
Almost the same problem in Request Dart Installation doesnt find dart:html
dart:html is only available in the browser. This is the error you get if you try to run code that uses it on the VM (instead of the browser). This is expected.
If you need to run your code outside of the browser (eg. in the VM as a CLI app or via Fluter) you cannot use dart:html. If you only want to use it in the browser but VS Code is trying to run your code in the VM, you'll need to set up some VS Code tasks/launch configs to run build_runner, similar to the Dart DevTools project:
https://github.com/flutter/devtools/tree/abe811f66e1bd36612b76bbe28250bc669a6ce08/.vscode
I've follow the instructions for dart libsass at:
https://github.com/oddrationale/dart_libsass
The compile step completes correctly. However - when i try and execute sassd.dart i get the following:
dart bin/sassd.dart ~/projects/web_apps_dart/lib/client/components/picker/picker.scss ~/Desktop/test.css
Cannot find extension library'package:libsass/libsass.dart': error: line 10 pos 1: library handler failed
import 'dart-ext:libsass/src/sass_extension';
^
Cannot find initialization function in extension'package:libsass/libsass.dart': error: line 10 pos 1: library handler failed
import 'dart-ext:sass_extension';
^
sass_extension.cc exists at ~/lib/src/sass_extension.cc
Question: How do we correctly import the sass_extions.cc file in recent builds of Dart?
I'm the author/maintainer of dart_libsass.
I got your bug report on GitHub and resolved the issue there. The issue was with the build script not the sass_extension.cc file itself. If you have any other issues, let's continue the discussion on the GitHub issues page. Thanks!
I cannot seem to install MDL for Dart. My files are very simple.
pubspec.yaml:
name: mdl_test
dependencies:
mdl: "^1.0.0"
browser: '^0.10.0'
di: "^3.3.4"
transformers:
- di
main.dart:
import 'package:mdl/mdl.dart' as mdl;
main() async {
mdl.registerMdl();
await mdl.componentFactory().run();
}
I am getting multiple errors. Example: Target of URI does not exist: package:logging/logging.dart - I checked, and logging is downloaded properly.
There are many "Target of URI does not exist" errors as well. It seems that packages in main.dart are imported fine, but packages installed with pub, that import other packages, are not working. Does anyone know why this is, or what the fix is? Thanks.
I'm boldly stepping into the world of AngularDart, admittedly not knowing too much Dart itself yet. I'm creating a new application that does nothing (yet), except includes the latest 'angular' package.
I'm using Dart 1.2.0 and AngularDart 0.9.9.
Very simple pubspec:
name: myapp
dependencies:
angular: any
My app layout:
pubspec.yaml
pubspec.lock
\lib
\packages
\web
In web I have a simple myapp.dart:
import 'package:angular/angular.dart';
main() {
}
My build seems to work fine, but I get the following warning:
Dart: Build
[Warning from Dart2JS on myapp|web/myapp.dart]:
packages\angular\angular.dart:31:23: Hint: Can't find 'animate' in the library 'angular'.
Is 'animate' spelled right?
#MirrorsUsed(targets: const [
^^^^^^^^
My question is, what does this mean, and is this anything to be concerned about?
This was a bug in AngularDart 0.9.9 and is fixed in current versions.