这是一个问题:我使用phamtomJS 2.1.1并且我想打开写在reactJS + typescript上的网页,我在System.import期间收到异常。
index.html的代码:
<div id="__Mount"></div>
<script src="lib/systemjs/dist/system.src.js"></script>
<script src="lib/react/dist/phantomjs-shims.js"></script>
<!-- build:js -->
<!-- endbuild -->
<!-- build:systemjs_config -->
<script>
System.config({
baseURL: './lib',
paths: {
"react*": 'react/dist/react-with-addons',
"react-dom": 'react-dom/dist/react-dom',
"jquery": 'kendoui/js/jquery.min',
"bootstrap": 'bootstrap/dist/js/npm'
}
});
System.defaultJSExtensions = true;
</script>
<!-- endbuild -->
<script>
System.import('client/mount').catch(function(e)
{
console.error(e);
});
</script>
mount.tsx代码:
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {App} from './app';
ReactDOM.render(<App/>, document.querySelector("#__Mount"));
还有一个app.tsx,其中包含应该在页面上的所有逻辑。 我使用以下命令从控制台运行phantomjs:
phantomjs test.js http://127.0.0.1:8080
哪个给我错误:
错误:错误:(SystemJS)eval @ [本机代码] __exec @ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:1544:18 执行@ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:4005:22 linkDynamicModule @ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:3281:36 链路@ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:3124:28 执行@ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:3491:17 doDynamicExecute @ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:774:32 链路@ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:972:36 doLink @ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:631:11 updateLinkSetOnLoad @ http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:677:24 http://127.0.0.1:8080/lib/systemjs/dist/system.src.js:493:30 评估http://127.0.0.1:8080/lib/client/mount.js 加载http://127.0.0.1:8080/lib/client/mount.js
时出错
test of test.js:
var page = require('webpage').create();
page.onError = function(msg) {
console.log("On error message "+msg);
};
page.open('http://127.0.0.1:8080/', function (status) {
console.log("status is: " + status);
if (status === "success") {
console.log("success");
setTimeout(function () {
console.log("screenshot");
page.render('screenshot.png');
var js = page.evaluate(function () {
return document;
});
console.log(js.all[0].outerHTML);
phantom.exit();
}, 10000);
}
else {
console.log("not success");
phantom.exit();
}
});
我真的很震惊,我无法找到方法。任何帮助或提示都将不胜感激。
答案 0 :(得分:1)
根据github:https://github.com/ariya/phantomjs/issues/14515
上的问题,目前尚不支持此功能所以我决定和电子http://electron.atom.io/一起去 现在它对我来说很好,它启动我的单元测试而不显示UI - 完美。