ember.js - Ember-CLI:修复 "' Ember' 未定义”?

标签 ember.js jslint ember-cli

当使用 Ember-CLI 并运行 ember 服务器时,我从 JSLint 收到以下错误:

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

添加 import Ember from 'ember'; 解决了这个问题。

这是现在处理我所有文件的官方方式吗?该文档尚未提及此更改。

最佳答案

编辑

来自斯蒂芬彭纳:

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.

不过,在那个日期之前,将它放在 .jshintrc 中可能会为您省去很多麻烦。

过时的答案

在您的 .jshintrc 文件(或tests/.jshintrc)中,将您不想在每个模块中定义的全局命名空间中的任何内容添加到预定义对象。例如:

{
  "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
}

在此示例中,我定义了 Ember(也可以定义 Em)、使用“$”的 jQuery 和 Modernizr。这将停止在终端中显示 jshint 错误消息。

这是根据 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."

关于ember.js - Ember-CLI:修复 "' Ember' 未定义”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24312362/

相关文章:

javascript - 控制台上出现 "[Report Only] Refused to load the font..."错误消息

javascript - 是否可以在 PhpStorm 中打开 JSLint 检查 Typescript 文件?

ember.js - Ember.Application.create 与 Ember.Application.extend

javascript - 登录 Ember.js

javascript - 错误子状态

javascript - 我已经在我的 javascript 文件上运行了 ESLint 工具。我已经解决了大部分问题,但我无法解决一条评论

ember.js - 无法启动守望者;回退到 NodeWatcher 来获取文件系统事件

model - Ember.js ArrayProxy 模型数组

javascript - 为什么 jslint 不喜欢 Object(obj)