【问题标题】:PhantomJS - error loading js file using System.importPhantomJS - 使用 System.import 加载 js 文件时出错
【发布时间】:2016-09-07 09:15:30
【问题描述】:

这里有一个问题:我正在使用 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 链接动态模块@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.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();
    }
});

我真的很感动,但我找不到办法。任何帮助或提示将不胜感激。

【问题讨论】:

    标签: javascript phantomjs systemjs


    【解决方案1】:

    根据 github 上的 issue:https://github.com/ariya/phantomjs/issues/14515,此功能尚不支持

    所以我决定和电子一起去http://electron.atom.io/ 现在它对我来说很好,它启动我的单元测试而不显示 UI - 完美。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2021-12-31
      相关资源
      最近更新 更多