{"id":19024,"library":"babel-plugin-angularjs-annotate","title":"babel-plugin-angularjs-annotate","description":"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.","status":"maintenance","version":"0.10.0","language":"javascript","source_language":"en","source_url":"https://github.com/schmod/babel-plugin-angularjs-annotate","tags":["javascript","angular","angularjs","di","dependency","injection","annotate","annotation","annotations"],"install":[{"cmd":"npm install babel-plugin-angularjs-annotate","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-angularjs-annotate","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-angularjs-annotate","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Requires Babel to be installed as a peer dependency; the plugin runs as a Babel transform.","package":"@babel/core","optional":false}],"imports":[{"note":"ESM default import works in modern setups; CJS require also works but may cause issues with some bundlers.","wrong":"const plugin = require('babel-plugin-angularjs-annotate');","symbol":"default","correct":"import plugin from 'babel-plugin-angularjs-annotate'"},{"note":"In Babel config, use the short name 'angularjs-annotate' (without the 'babel-plugin-' prefix).","wrong":"module.exports = { plugins: ['babel-plugin-angularjs-annotate'] };","symbol":"plugin","correct":"module.exports = { plugins: ['angularjs-annotate'] };"},{"note":"Options are passed as array of [name, options]; explicitOnly expects boolean, not string.","wrong":"module.exports = { plugins: [['angularjs-annotate', { explicitOnly: 'true' }]] };","symbol":"options","correct":"module.exports = { plugins: [['angularjs-annotate', { explicitOnly: true }]] };"}],"quickstart":{"code":"# Install plugin\nnpm install --save-dev babel-plugin-angularjs-annotate\n\n# .babelrc or babel.config.js configuration\n{\n  \"presets\": [\"@babel/preset-env\"],\n  \"plugins\": [\"angularjs-annotate\"]\n}\n\n# Example input (app.js):\nclass MyService {\n  constructor($http, $q) {\n    this.$http = $http;\n    this.$q = $q;\n  }\n}\nangular.module('app').service('MyService', MyService);\n\n# Output after Babel transformation:\nclass MyService {\n  constructor($http, $q) {\n    this.$http = $http;\n    this.$q = $q;\n  }\n}\nMyService.$inject = ['$http', '$q'];\nangular.module('app').service('MyService', MyService);","lang":"javascript","description":"Install the plugin, configure it in Babel, and see implicit class annotation output."},"warnings":[{"fix":"Use regular functions for services and providers: angular.module('app').service('MySvc', function($http) { ... });","message":"Arrow functions in Angular service/provider declarations lose `this` context. The plugin will still add annotations, but the app won't work.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Replace 'ngInject' string with `/* @ngInject */` comment annotation.","message":"The plugin uses `@ngInject` comments; the 'ngInject' string directive is deprecated in favor of `/* @ngInject */`.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure all functions needing DI have explicit `/* @ngInject */` comment or set `explicitOnly: false`.","message":"If using `explicitOnly: true`, the plugin will not annotate implicit patterns. Unexpected missing annotations may occur if developers forget `@ngInject`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Manually add static $inject property if you prefer property-style annotation, or rely on plugin's output.","message":"Class property annotations (e.g., static $inject) are not added; the plugin only adds `$inject` after the class declaration.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev babel-plugin-angularjs-annotate` and ensure it's in devDependencies.","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'babel-plugin-angularjs-annotate'"},{"fix":"Add AngularJS (e.g., `npm install angular`) and include it via script tag or bundler entry.","cause":"AngularJS library not included in the build or global scope.","error":"ReferenceError: angular is not defined"},{"fix":"Ensure Babel 6+ is installed; check that the plugin is in the 'plugins' array (not 'presets').","cause":"Plugin used with unsupported Babel version or incorrect config.","error":"TypeError: Cannot read property 'push' of undefined (at addInjectCode)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}