React Native packager不包括捆绑包中的第三方库

时间:2017-08-23 21:04:08

标签: reactjs react-native

调试react-native packager的最佳方法是什么,不包括输出包中的依赖项?我有什么:

  1. 模块包含在package.json中,并显示在我的node_modules
  2. 我正在使用typescript,编译后的js文件有require('countdown')行。
  3. 如果我检查输出包或记录var countdown = require('countdown'),我可以看到包中没有包含countdown.js的来源。
  4. 如果我使用webpack创建一个Web包,它会按预期工作。
  5. 这是编译后的js代码,它有问题:

    "use strict";
    var __extends = (this && this.__extends) || (function () {
        var extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return function (d, b) {
            extendStatics(d, b);
            function __() { this.constructor = d; }
            d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
        };
    })();
    Object.defineProperty(exports, "__esModule", { value: true });
    var RX = require("reactxp");
    var countdown = require("countdown");
    var styles = {
        outerContainer: RX.Styles.createViewStyle({
            flexDirection: "row"
        }),
        innerContainer: RX.Styles.createViewStyle({
            flexDirection: "column",
            alignItems: "center",
            paddingHorizontal: 5
        })
    };
    var CountdownTimer = (function (_super) {
        __extends(CountdownTimer, _super);
        function CountdownTimer() {
            var _this = _super.call(this) || this;
            _this._setStateToNow = function () {
                _this.setState({ currentDate: new Date(Date.now()) });
            };
            _this.state = { currentDate: new Date() };
            return _this;
        }
        CountdownTimer.prototype.componentDidMount = function () {
            this.timerId = setInterval(this._setStateToNow, 1000);
        };
        CountdownTimer.prototype.componentWillUnmount = function () {
            clearInterval(this.timerId);
        };
        CountdownTimer.prototype.render = function () {
            // THIS LINE FAILS SINCE 'countdown' is {}
            var diff = countdown(this.state.currentDate, this.props.untilDate, CountdownTimer.DIFF_ARGS);
    
            ....
    
        };
        CountdownTimer.DIFF_ARGS = countdown.DAYS |
            countdown.HOURS |
            countdown.MINUTES |
            countdown.SECONDS;
        return CountdownTimer;
    }(RX.Component));
    exports.CountdownTimer = CountdownTimer;
    

    我得到的错误是Object is not a function,并且记录var倒计时显示它是{},并且检查index.android.bundle表明countdown.js的源代码是不包括在内。

    我正在使用node ./node_modules/react-native/local-cli/cli.js start

    运行打包程序

0 个答案:

没有答案