2016-09-06 100 views
0

我正在使用PhantomJS为茉莉花测试设置CI。我正在面对将SystemJS包含在我的html页面中的问题。我从它删除的一切,刚刚离开的JavaScript,仍然面临着同样的错误:在html中加载SystemJS最终在PhantomJS中出错

ReferenceError: Can't find variable: System

下面是HTML的例子:

<!DOCTYPE html> 
<html> 
    <head> 
    </head> 
    <body> 
     <script src="lib/systemjs/dist/system.src.js"> </script> 
     <script> 
      System.config({ 
       baseURL: './lib' 

      }); 
     </script> 
    </body> 
</html> 

我跑了它在这样的控制台:phantomjs test.js http://localhost:8080

test.js包含下面的代码:

var page = require('webpage').create(); 
page.open(system.args[1], function(status) 
{ 
    phantom.exit(0); 
}); 

看起来它没有看到system.src.js。我试图把绝对路径 - 但仍然是相同的错误。也尝试与page.injectJs - 也不好。

+0

您使用哪个PhantomJS版本?请注册onConsoleMessage,onError,onResourceError,onResourceTimeout事件([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-1_phantomerrors-js))。也许有错误。 –

+0

我使用PhantomJS 2,我没有收到其他错误,只有我上面写的那个。 – Katia

回答

1

过了一段时间我找到了答案,我想分享它,也许有人会觉得它有用。我记录了page.outerHTML,并且看到了使用system.src.js而不是脚本,我使用了system-polyfills.js。它看起来就像是:

<script src="lib/systemjs/dist/system.src.js"></script> 
<script type="text/javascript" src="http://127.0.0.1:8080/lib/systemjs/dist/system-polyfills.js"> 

所以我刚才添加缺少的系统polyfills.js到以下文件夹,并将其固定的错误。尽管我仍然不知道它是从哪里来的。