gpt4 book ai didi

requirejs - 使用 PhantomJS 运行 RequireJS/WireJS 应用程序

转载 作者:行者123 更新时间:2023-12-05 00:28:05 33 4
gpt4 key购买 nike

我正在尝试执行一个使用 RequireJS (2.1.8)、WireJS (0.10.2) 和 PhantomJS (1.9.2) 的基本应用程序:

  • 使用 PhantomJS 运行应用程序时(这是我的目标),WireJS 无法加载(请参阅下面的错误)。
  • 使用 Chrome 运行应用程序时,它会正确完成。

  • 请帮忙指出 WireJS 在 PhantomJS 下正常运行的缺失部分。

    以下是我的应用程序文件。

    1) 应用程序.html
    <!DOCTYPE html>

    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>SaphirJS.core</title>
    <script data-main="app" src="../../../target/deps/require-0.0.1/2.1.8/require.js"> </script>
    </head>
    <body>
    </body>
    </html>

    2)app.js
    "use strict";

    require.config({
    baseUrl: ".",

    packages: [
    { name: 'wire', location: '../../../target/deps/wire-0.0.1/0.10.2', main: 'wire' },
    { name: 'when', location: '../../../target/deps/when-0.0.1/2.4.1', main: 'when' },
    { name: 'meld', location: '../../../target/deps/meld-0.0.1/1.3.0', main: 'meld' }
    ]
    });

    require(["wire!wireContext"], function(wireContext) {
    alert(wireContext.message);
    });

    3)wireContext.js
    define({
    message: "Hello World!"
    });

    4) phantom-runner.js
    (function() {
    'use strict';

    var args = require('system').args,
    timeoutRef = undefined,
    timeLimit = 10000;

    // arg[0]: scriptName, args[1...]: arguments
    if (args.length !== 2) {
    console.error('Usage:\n phantomjs runner.js [url-of-your-qunit-testsuite]');
    phantom.exit(1);
    }

    var url = args[1],
    page = require('webpage').create();

    // Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`)
    page.onConsoleMessage = function(msg) {
    console.log(msg);
    };

    page.onInitialized = function() {
    timeoutRef = setTimeout(function(){
    console.error('Test Run Failed. Timeout Exceeded. Took longer than '+ timeLimit / 1000 +' seconds.');
    phantom.exit(1);
    }, timeLimit);
    };

    page.onAlert = function(message) {
    clearTimeout(timeoutRef);
    phantom.exit(0);
    };

    page.open(url, function(status) {
    if (status !== 'success') {
    console.error('Unable to access network: ' + status);
    phantom.exit(1);
    }
    });
    })();

    5) PhantomJS下运行app时报错
    TypeError: 'undefined' is not a function (evaluating 'Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty)')

    <path-to-deps>/wire-0.0.1/0.10.2/lib/object.js:13
    <path-to-deps>/require-0.0.1/2.1.8/require.js:1635
    <path-to-deps>/require-0.0.1/2.1.8/require.js:871
    <path-to-deps>/require-0.0.1/2.1.8/require.js:1142
    <path-to-deps>/require-0.0.1/2.1.8/require.js:779
    <path-to-deps>/require-0.0.1/2.1.8/require.js:1169 in callGetModule
    <path-to-deps>/require-0.0.1/2.1.8/require.js:1529
    <path-to-deps>/require-0.0.1/2.1.8/require.js:1656
    Error: Load timeout for modules: wire!wireContext_unnormalized2
    http://requirejs.org/docs/errors.html#timeout

    <path-to-deps>/require-0.0.1/2.1.8/require.js:138 in defaultOnError
    <path-to-deps>/require-0.0.1/2.1.8/require.js:536 in onError
    <path-to-deps>/require-0.0.1/2.1.8/require.js:691 in checkLoaded
    <path-to-deps>/require-0.0.1/2.1.8/require.js:710

    Test Run Failed. Timeout Exceeded. Took longer than 10 seconds.

    最佳答案

    你是对的,尤尼斯。 PhantomJS 不支持 Function.prototype.bind因为某些原因。

    您可以 polyfill Function.prototype.bind通过使用 cujoJS/polykriskowal/es5-shim .

    关于requirejs - 使用 PhantomJS 运行 RequireJS/WireJS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19451808/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com