JavaScript dependency checker/fixer for Closure Library based on Esprima

npm install fixclosure
4 downloads in the last day
48 downloads in the last week
120 downloads in the last month

fixclosure Build Status Dependency Status Coverage Status

fixclosure is JavaScript dependency checker/fixer for Closure Library based on Esprima.
It finds namespaces used in a JavaScript file and insert/remove goog.provide / goog.require automatically.


$ npm install -g fixclosure


Following foo.js requires an unused namespace goog.unused. Also goog.missing is used but not required.

// foo.js (before)

goog.require('goog.unused'); = function() {;

Fix it !

$ fixclosure --fix-in-place foo.js
File: foo.js


- goog.unused

Missing Require:
- goog.missing

Unnecessary Require:
- goog.unused


1 files fixed

Fixed !
goog.require('goog.unused') is removed and goog.require('goog.missing') is inserted.

// foo.js (fixed!)

goog.require('goog.missing'); = function() {;

Rules fixclosure checked

fixclosure checks and fixes:

  • Duplicated require/provide
  • Missing require/provide
  • Unnecessary require/provide

gjslint beforehand

Run Closure Linter (gjslint) before fixclosure. fixclosure is based on the assumption that target files are linted by it.

Use with Grunt

Use grunt-fixclosure plugin.

Configuration file

fixclosure loads options from .fixclosurerc config file like:

--roots foo,bar
--namespaceMethods foo.foo1,bar.bar1

fixclosure will find the file in the current directory and, if not found, will move one level up the directory tree all the way up to the filesystem root.


-f or --fix-in-place

If an invalid file is found, fixclosure fixes the file in place.


.fixclosurerc file path.
Specify if your file is not in the search path.


Specify your root namespaces in addition to default roots goog,proto2,soy,soydata,svgpan.
Comma separated list.


Specify method or property exported as a namespace itself like goog.dispose.
Comma separated list.


Replace method or property to namespace mapping like goog.disposeAll:goog.dispose.
Comma separated list of colon separated pairs like foo.bar1:foo.bar2,foo.bar3:foo.bar4.


Show not only failed files but also passed files.


Disable color output.

Inline hint

fixclosure reads "hint" for lint from special comments in your code.


Suppress goog.require auto removing.

goog.require(''); // fixclosure: suppressUnused

In the above, goog.require('') will not removed by fixclosure even if it isn't used in the file. The hint affects only same line. Useful in module declaration.


Suppress goog.require auto insertion.

// fixclosure: suppressRequire;

In the above, goog.require('foo') will not inserted by fixclosure. The hint affects only next line. This is useful to workaround cyclic reference.


  • 1.0.1
    • Fix --no-color #37
  • 1.0.0
    • Some features, bug fixes and breaking changes. See release note .
  • 0.2.1 (2013/11/21)
    • Fix --replaceMap
  • 0.2.0 (2013/11/15)
    • Add .fixclosurerc
    • Add --no-color
  • 0.1.5 (2013/11/15)
    • Update dependencies.
  • 0.1.3 (2012/12/08)
    • Append package methods of Closure Library.
    • Change version option from -V to -v.
    • Change exit code of invalid argument to 1.
    • Fix for private properties.
  • 0.1.2 (2012/11/28)
    • Supports const property correctly.
    • Supports a method starting with "$".
    • Ignore
    • Don't provide @typedef type resources.
    • Fix #5 don't provide a private class.
    • Fix #6 Don't require a private method defined in the same file.
    • Add some package methods.
  • 0.1.1 (2012/11/25)
    • Scope check (by piglovesyou)
    • Root package filter works for toProvide list.
  • 0.1.0 Add some options
    • Changes "fix in place" option to "-f" from "-i"
    • Implements root package filter (default: "goog")
    • Adds options --roots, --namespaceMethods and --replaceMap
  • 0.0.2 Bugfix
  • 0.0.1 Initial release


MIT License: Teppei Sato

npm loves you