Можно ли импортировать этот пакет npm? - PullRequest
0 голосов
/ 08 мая 2018

Здравствуйте, я пытаюсь импортировать пакет npm с именем "jquery.terminal" в мой проект.

Я использую browserify через командную строку для преобразования require ("jquery.terminal"); перевод в читаемый код интерпретатором.

Вот мой текущий код.

require("jquery.terminal");

jQuery(function($, undefined) {
    $('#term_demo').terminal(function(command) {
        if (command !== '') {
            try {
                var result = window.eval(command);
                if (result !== undefined) {
                    this.echo(new String(result));
                }
            } catch(e) {
                this.error(new String(e));
            }
        } else {
           this.echo('');
        }
    }, {
        greetings: 'JavaScript Interpreter',
        name: 'js_demo',
        height: 200,
        prompt: 'js> '
    });
});

вот пакет по npm https://github.com/jcubic/jquery.terminal

Вот моя ошибка

jQuery.Deferred exception: $(...).terminal is not a function TypeError: $(...).terminal is not a function
    at HTMLDocument.<anonymous> (file:///C:/Dev/term-game/bundle.js:6:21)
    at mightThrow (file:///C:/Dev/term-game/bundle.js:11049:29)
    at process (file:///C:/Dev/term-game/bundle.js:11117:12) undefined
jQuery.Deferred.exceptionHook @ bundle.js:11333
process @ bundle.js:11121
setTimeout (async)
(anonymous) @ bundle.js:11155
fire @ bundle.js:10783
fireWith @ bundle.js:10913
fire @ bundle.js:10921
fire @ bundle.js:10783
fireWith @ bundle.js:10913
ready @ bundle.js:11393
completed @ bundle.js:11403
bundle.js:6 Uncaught TypeError: $(...).terminal is not a function
    at HTMLDocument.<anonymous> (bundle.js:6)
    at mightThrow (bundle.js:11049)
    at process (bundle.js:11117)

1 Ответ

0 голосов
/ 08 мая 2018

Вам необходимо включить jQuery, чтобы у вас был объект jQuery, а затем jQuery Terminal, а также UMD. Для использования jQuery Terminal требуется вызвать функцию и передать ей все зависимости, которые в данном случае являются просто jQuery.

var $ = require('jquery');
require('jquery.terminal')($);

$('#term').terminal();
...