schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
https://jasprpad.schultek.de
MIT License
1.07k stars 65 forks source link

Error: Dart library 'dart:js_util' is not available on this platform. #117

Closed exaby73 closed 11 months ago

exaby73 commented 11 months ago

Description

When using jaspr generate, platform imports do not work.

Steps To Reproduce

Have a platform import in one of your files. This is a snippet of my code:

import 'dart:async';

import 'package:jaspr/html.dart';

@Import.onWeb('dart:html', show: [#PointerEvent])
// ignore: always_use_package_imports
import 'events.imports.dart';

/// Type safe click handler
EventCallback click(FutureOr<void> Function(PointerEvent event) callback) {
  return (event) async {
    if (event is! PointerEventOrStubbed) {
      print('event is not a PointerEventOrStubbed');
      return;
    }
    event.preventDefault();
    await callback(event);
  };
}

The above function can be used in a Component like so:

yield button(
  events: {
    'click': click((/*PointerEvent*/ event) {
      doSomething();
    }),
  }. 
  [text('Foo')],
);

Expected Behavior

jaspr generate should work

Error logs

$ jaspr generate
✓ [CLI] Completed building web assets. (7.4s)
✗ [SERVER] [ERROR] lib/app.dart:1:8: Error: Dart library 'dart:js_util' is not available on this platform. (1.2s)
[SERVER] [ERROR] import 'dart:js_util';
[SERVER] [ERROR] ^
[SERVER] [ERROR] Context: The unavailable library 'dart:js_util' is imported through these packages:
[SERVER] [ERROR] 
[SERVER] [ERROR] package:my_app => dart:js_util
[SERVER] [ERROR] 
[SERVER] [ERROR] Detailed import paths for (some of) the these imports:
[SERVER] [ERROR] 
[SERVER] [ERROR] package:my_app/main.dart => package:my_app/app.dart => dart:js_util
✗ [SERVER]  (0ms)

Additional Information

Snippet of pubspec.yaml:

dependencies:
  jaspr: ^0.9.0
  jaspr_router: ^0.3.0

dev_dependencies:
  build_runner: ^2.4.0
  build_web_compilers: ^4.0.5
  jaspr_builder: ^0.9.0
  jaspr_tailwind: ^0.1.0
  lint: ^2.1.2

jaspr:
  uses-ssr: true

dart --version output:

Dart SDK version: 3.1.1 (stable) (Tue Sep 5 12:20:14 2023 +0000) on "macos_arm64"
exaby73 commented 11 months ago

This seems to also be reproducible with jaspr build. If this is indeed an error on my end, this issue could also be considered a documentation issue.

exaby73 commented 11 months ago

Sorry, there was a rouge import :p I'll close the issue now