Skip to content
pubscout

amdjs

3.0.0, released 6 weeks ago by an unverified publisher

Dart package to load JavaScript libraries that use AMD (RequireJS) in web apps.

WASM-ready
$ flutter pub add amdjs
Source repository

What it does

It checks if a native AMD implementation is present and, if not, injects <script> tags to load the library. It also exposes a Dart API to require modules and optionally expose global JS variables.

AI-written summary of version 3.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to use a JS library that relies on AMD in a Dart web project.
  • You want to avoid script loading conflicts with Dart’s own AMD loader in development mode.

Skip it when

  • You are building a non-web Dart app (e.g., Flutter mobile).
  • You already have a native AMD loader like RequireJS included manually.

Strengths

  • Handles both native AMD and fallback script injection.
  • Supports async loading and global variable exposure.
  • Fully null‑safe and uses dart:js_interop.
  • Well tested with integration tests against RequireJS.

Weaknesses

  • Only works on web; no support for mobile or desktop Flutter.
  • Requires manual script paths or package names; not a code generator.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Add dependency in pubspec and import 'package:amdjs/amdjs.dart'; no build_runner needed.

import 'package:amdjs/amdjs.dart';

void main() async {
  var ok = await AMDJS.require('jquery', '/js/jquery.js', globalJSVariableName: 'jquery');
  if (ok) print('jQuery loaded');
}

Alternatives

Packages that do the same job and could replace amdjs.

Works with

Packages commonly used together with amdjs: ones it builds on, ones built on it, and its own family.