Registry / serialization / babel-plugin-angularjs-annotate

babel-plugin-angularjs-annotate

JSON →
library0.10.0jsnpmunverified

A Babel plugin that adds Angular 1.x dependency injection annotations to ES5/ES6 code, supporting both explicit (`/* @ngInject */`) and automatic (implicit) annotation of common Angular patterns. Version 0.10.0 is the latest stable release; the plugin is in maintenance mode with infrequent updates. It is a fork of ng-annotate optimized for Babel users, offering reduced build times by avoiding a separate tool. It fully supports ES5, transpiled ES6, and raw ES6, including ES6 classes and arrow functions not covered by ng-annotate. Key differentiators: integration with Babel pipeline, ES6+ support, and `explicitOnly` option to restrict annotation to marked functions only.

npm install babel-plugin-angularjs-annotate
INSTALL
IMPORT
SIG · BABEL-PLUGIN-ANGUL
B
babel-plugin-angularjs-annotate
serializationjavascriptv0.10.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import plugin from 'babel-plugin-angularjs-annotate'
const plugin = require('babel-plugin-angularjs-annotate');
ESM default import works in modern setups; CJS require also works but may cause issues with some bundlers.
plugin
module.exports = { plugins: ['angularjs-annotate'] };
module.exports = { plugins: ['babel-plugin-angularjs-annotate'] };
In Babel config, use the short name 'angularjs-annotate' (without the 'babel-plugin-' prefix).
options
module.exports = { plugins: [['angularjs-annotate', { explicitOnly: true }]] };
module.exports = { plugins: [['angularjs-annotate', { explicitOnly: 'true' }]] };
Options are passed as array of [name, options]; explicitOnly expects boolean, not string.

Install the plugin, configure it in Babel, and see implicit class annotation output.

# Install plugin npm install --save-dev babel-plugin-angularjs-annotate # .babelrc or babel.config.js configuration { "presets": ["@babel/preset-env"], "plugins": ["angularjs-annotate"] } # Example input (app.js): class MyService { constructor($http, $q) { this.$http = $http; this.$q = $q; } } angular.module('app').service('MyService', MyService); # Output after Babel transformation: class MyService { constructor($http, $q) { this.$http = $http; this.$q = $q; } } MyService.$inject = ['$http', '$q']; angular.module('app').service('MyService', MyService);
Debug
Known issues
gotchaArrow functions in Angular service/provider declarations lose `this` context. The plugin will still add annotations, but the app won't work.
fix
Use regular functions for services and providers: angular.module('app').service('MySvc', function($http) { ... });
affects: >=0.1.0
deprecatedThe plugin uses `@ngInject` comments; the 'ngInject' string directive is deprecated in favor of `/* @ngInject */`.
fix
Replace 'ngInject' string with `/* @ngInject */` comment annotation.
affects: >=0.1.0
gotchaIf using `explicitOnly: true`, the plugin will not annotate implicit patterns. Unexpected missing annotations may occur if developers forget `@ngInject`.
fix
Ensure all functions needing DI have explicit `/* @ngInject */` comment or set `explicitOnly: false`.
affects: >=0.1.0
gotchaClass property annotations (e.g., static $inject) are not added; the plugin only adds `$inject` after the class declaration.
fix
Manually add static $inject property if you prefer property-style annotation, or rely on plugin's output.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-angularjs-annotate'
Plugin not installed or not in node_modules.
fix
Run `npm install --save-dev babel-plugin-angularjs-annotate` and ensure it's in devDependencies.
ReferenceError: angular is not defined
AngularJS library not included in the build or global scope.
fix
Add AngularJS (e.g., `npm install angular`) and include it via script tag or bundler entry.
TypeError: Cannot read property 'push' of undefined (at addInjectCode)
Plugin used with unsupported Babel version or incorrect config.
fix
Ensure Babel 6+ is installed; check that the plugin is in the 'plugins' array (not 'presets').
Upgrade
Version history
0.10.0latest on npm
Audit
Dependencies
@babel/corerequiredRequires Babel to be installed as a peer dependency; the plugin runs as a Babel transform.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
babel-plugin-angularjs-annotate — npm install babel-plugin-angularjs-annotate · libregistry