question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Library isn't bundled by react native packager

See original GitHub issue

I’m sure this is something I’m doing wrong, but I can’t figure it out and I’m hoping someone here might have some experience with this.

For some reason, when I require this library and bundle my source code with the react native packager, the source of this library doesn’t get bundled and therefore I get exceptions when calling the functions. I’m using typescript and have tried all the known ways of importing, and also have tried changing the .js source that is compiled.

What I have:

  1. Module is included in package.json and appears in my node_modules
  2. I’m using typescript, and the compiled js file has the require(‘countdown’) line.
  3. If I inspect the output bundle, or log the var countdown = require(‘countdown’), I can see that the source for countdown.js isn’t included in the bundle.
  4. If I use webpack to create a web bundle, it works as expected.

Here’s the compiled js code which is having issues:

"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;

I have this library setup and imported the exact same way as others (e.g. lodash, reactxp), and this is the only one that doesn’t get bundled.

I’m running the packager the standard way, and have tried clearing node_modules and all the caches.

Here’s an SO question I also opened to try get some help:

I have even tried adding a require call to my root index.js, which also doesn’t work

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
matheusmatoscommented, Aug 25, 2017

Hi, I went through something similar, using react native too.

Probably it’s caused by the way of the module is exported.

I’ve solved changing the source code. Take a look:

...

/**
 * @public
 * @type {Object|null}
 */
// just comment this line, it'll fix the NodeJS package
// but will crash the use in the browser :\ 
// var module;

/**
 * API entry
 * @public
 * @param {function(Object)|Date|number} start the starting date
 * @param {function(Object)|Date|number} end the ending date
 * @param {number} units the units to populate
 * @return {Object|number}
 */
var countdown = (
    ...
)(module);

I’ll submit a PR suggesting this.

1reaction
sam-infinitycommented, Apr 20, 2021

@mckamey Can you release the fixed version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native error after installing third party library
This error normally comes when your device not been able to load bundle from react-native packager please make sure your are loading your...
Read more >
iOS main.jsbundle does not exists – Bundle React Native ...
In my case, I found it's because I'm using typescript. Open Project > Build Phases > Bundle React Native code and images. ......
Read more >
Using Libraries - React Native
React Native provides a set of built-in Core Components and APIs ready to use in your app. You're not limited to the components...
Read more >
Drastically Faster Bundling in React Native | by Evan Bacon
This project is aimed at shifting the React Native ecosystem to ship better libraries and making Metro bundler work more like a web...
Read more >
Optimizing Performance - React
bundle.js. Remember that you only need to do this for production builds. You shouldn't apply these plugins in development because they will hide...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found