“ReferenceError:找不到变量:require”(使用babel.js输出)

时间:2016-01-22 04:34:58

标签: javascript gulp phantomjs babeljs qunit

我的PhantomJS Runner似乎并不知道esModule

我的es2015代码由babel.js解析并转换为es5代码 当我运行qunit-phantomjs-runner时,我收到此错误

..../myapp/node_modules/phantomjs/lib/phantom/bin/phantomjs ..../myapp/node_modules/qunit-phantomjs-runner/runner.js file:////..../myapp/tests/index.html
ReferenceError: Can't find variable: require

  file:////..../myapp/.tmp/js/app.js:5

Test failed: global failure
    Failed assertion: TypeError: 'undefined' is not an object (evaluating 'App.rootElement = '#ember-testing'')
file:////..../myapp/tests/tests.js:2

这是'TestSuite'我在跑步者中通过此命令传入phantomjs:

page = require('webpage').create();
...
...
page.open(url, function (status) { ... }); //url is the test/index.html file

这是index.html文件本身:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ember Starter Kit</title>
  <link rel="stylesheet" href="runner.css">
  <link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
  <div id="ember-testing-container">
    <div id="ember-testing"></div>
  </div>

  <script src="../bower_components/jquery/dist/jquery.js"></script>
  <script src="../bower_components/ember/ember.debug.js"></script>
  <script src="../.tmp/js/compiled-templates.js"></script>
  <script src="../.tmp/js/app.js"></script>
  <script src="../bower_components/qunit/qunit/qunit.js"></script>
  <script src="tests.js"></script>
</body>
</html>

以及导致问题的代码:

/* global Ember */

'use strict';

var _ember = require('ember'); // <--- breaks at this line, also if i try to access exports variable

var _ember2 = _interopRequireDefault(_ember);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var App = _ember2.default.Application.create();

App.Router.map(function () {});

App.IndexRoute = _ember2.default.Route.extend({
  model: function model() {
    return ['red', 'yellow', 'blue'];
  }
});

similar个问题aren'thelpme

我正在使用

  • “babel-core”:“^ 6.4.5”
  • “babel-preset-es2015”:“^ 6.3.13”
  • “gulp-qunit”:“^ 1.3.0”
  • “gulp”:“^ 3.9.0”
  • “phantomjs”:“^ 1.9.0”

0 个答案:

没有答案