Search code examples
ember.jsjslintember-cli

Ember-CLI: Fix for "'Ember' is not defined"?


When using Ember-CLI and running ember server, I get the following error from JSLint:

[app_path]/filename.js: line 1, col 16, 'Ember' is not defined.

Adding import Ember from 'ember'; fixes this.

Is this the official way to go now on all my files? The documentation does not mention this change yet.


Solution

  • EDIT

    From Stephan Penner:

    We explicitly left it [Ember] out [of the .jshintrc file], please import ember instead.

    We plan on exposing more and more of ember as es6, someday this will allow the tooling to remove parts of ember you are not using. Resulting in smaller builds.

    Still, until that date it's probably going to save you a lot of hassle to put it in .jshintrc.

    OUTDATED ANSWER

    In your .jshintrc file (ortests/.jshintrc), add anything in the global namespace you don't want to have to define in each module to the predef object. For example:

    {
      "predef": {
        "document": true,
        "window": true,
        "SprintStatusENV": true,
        "Ember": true, // Added
        "$": true, // ADDED
        "Modernizr": true // ADDED
      },
      "browser" : true,
      "boss" : true,
      "curly": true,
      "debug": false,
      "devel": true,
      "eqeqeq": true,
      "evil": true,
      "forin": false,
      "immed": false,
      "laxbreak": false,
      "newcap": true,
      "noarg": true,
      "noempty": false,
      "nonew": false,
      "nomen": false,
      "onevar": false,
      "plusplus": false,
      "regexp": false,
      "undef": true,
      "sub": true,
      "strict": false,
      "white": false,
      "eqnull": true,
      "esnext": true,
      "unused": true
    }
    

    In this example, I define Ember (could also define Em), jQuery using '$' and Modernizr. This will stop the jshint error messages appearing in the terminal.

    This is per the ember-cli docs:

    "If you want to use external libraries that write to a global namespace (e.g. moment.js), you need to add those to the predef section of your project’s .jshintrc file and set its value to true. If you use the lib in tests, need to add it to your tests/.jshintrc file, too."