无法使浏览器工作,给出参考错误

时间:2015-01-11 17:04:34

标签: node.js browserify bitcore

我正在尝试构建bitcore以便在浏览器中运行。这些是我跑的命令:

npm install bitcore

我创建了一个名为index.js的文件:

var Address = require('bitcore/lib/address');
var Block = require('bitcore/lib/block');
var BlockHeader = require('bitcore/lib/blockheader');
var HDPrivateKey = require('bitcore/lib/hdprivatekey');
var HDPublicKey = require('bitcore/lib/hdpublickey');
var PaymentProtocol = require('bitcore/lib/paymentprotocol');
var PrivateKey = require('bitcore/lib/privatekey');
var PublicKey = require('bitcore/lib/publickey');
var Script = require('bitcore/lib/script');
var Transaction = require('bitcore/lib/transaction');
var URI = require('bitcore/lib/uri');
var Unit = require('bitcore/lib/unit');

(直接来自bitcore docs:http://bitcore.io/guide/browser.html

然后我运行了这个命令:

browserify index.js -o bitcore-browser.js

似乎有效。以下是输出文件的前几行:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var Address = require('bitcore/lib/address');
var Block = require('bitcore/lib/block');
var BlockHeader = require('bitcore/lib/blockheader');
var HDPrivateKey = require('bitcore/lib/hdprivatekey');
var HDPublicKey = require('bitcore/lib/hdpublickey');
var PaymentProtocol = require('bitcore/lib/paymentprotocol');
var PrivateKey = require('bitcore/lib/privatekey');
var PublicKey = require('bitcore/lib/publickey');
var Script = require('bitcore/lib/script');
var Transaction = require('bitcore/lib/transaction');
var URI = require('bitcore/lib/uri');
var Unit = require('bitcore/lib/unit');

},{"bitcore/lib/address":2,"bitcore/lib/block":3,"bitcore/lib/blockheader":4,"bitcore/lib/hdprivatekey":18,"bitcore/lib/hdpublickey":19,"bitcore/lib/paymentprotocol":24,"bitcore/lib/privatekey":28,"bitcore/lib/publickey":29,"bitcore/lib/script":30,"bitcore/lib/transaction":33,"bitcore/lib/unit":42,"bitcore/lib/uri":43}],2:[function(require,module,exports){
(function (Buffer){
'use strict';

(我假设它意味着它正常工作。文件大约是2MB。)

当我将文件添加到页面时,没有任何对象存在:

<!DOCTYPE html>
<html>
    <head>
        <script src="bitcore.browser.js"></script>
    </head>
    <body>
        <script>
            var p = new PrivateKey(); // ReferenceError: PrivateKey is not defined
        </script>
    </body>
</html>

我甚至试图运行“uglify”,但这没有效果。

0 个答案:

没有答案