Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: bignumber is not a constructor, nodejs webpack bundle #88

Closed
dapplion opened this issue Oct 7, 2018 · 11 comments
Closed

TypeError: bignumber is not a constructor, nodejs webpack bundle #88

dapplion opened this issue Oct 7, 2018 · 11 comments

Comments

@dapplion
Copy link

dapplion commented Oct 7, 2018

In a nodejs app bignumber.js throws in initialization.

const MINUS_ONE = new bignumber(-1)
                  ^
TypeError: bignumber is not a constructor
    at Object.<anonymous> (/usr/src/app/server.bundle.js:33351:19)
    at __webpack_require__ (/usr/src/app/server.bundle.js:20:30)
    at Object.<anonymous> (/usr/src/app/server.bundle.js:24786:16)
    at __webpack_require__ (/usr/src/app/server.bundle.js:20:30)
    at Object.module.exports (/usr/src/app/server.bundle.js:85704:17)
    at __webpack_require__ (/usr/src/app/server.bundle.js:20:30)
    at Object.<anonymous> (/usr/src/app/server.bundle.js:50098:21)
    at __webpack_require__ (/usr/src/app/server.bundle.js:20:30)
    at Object.<anonymous> (/usr/src/app/server.bundle.js:48238:12)
    at __webpack_require__ (/usr/src/app/server.bundle.js:20:30)

bignumber version is 6.0.0, required by:

dnp_dappmanager@0.1.0 /path/build/src
└─┬ autobahn@18.3.2
  └─┬ cbor@4.0.0
    └── bignumber.js@6.0.0

bignumber is used in a webpack bundle, on node version is LTS 8.12.0, inside a docker container with image node:8.12.0-alpine in an ubuntu server host.

The code referenced by the stack is:

function(module, exports, __webpack_require__) {

"use strict";


const bignumber = __webpack_require__(62)
const utils = __webpack_require__(80)
const url = __webpack_require__(63)

const MINUS_ONE = new bignumber(-1)
const TEN = new bignumber(10)
const TWO = new bignumber(2)

/**
 * A CBOR tagged item, where the tag does not have semantics specified at the
 * moment, or those semantics threw an error during parsing. Typically this will
 * be an extension point you're not yet expecting.
 */
class Tagged {

Any help and how to fix the issue would be greatly appreciated!

@hildjj
Copy link
Owner

hildjj commented Oct 8, 2018

can you put together a small webpack example that would let me recreate this on my own system? That might help me on #87 anyway.

@tobowers
Copy link

I'm having this problem using parcel too

@hildjj
Copy link
Owner

hildjj commented Jan 25, 2019

Are you bundling bignumber.js (https://github.com/MikeMcl/bignumber.js)?

@tobowers
Copy link

Thanks for the quick response. I put together a minimal failure case https://github.com/quorumcontrol/minimal-fail-bignumber/tree/master/cbor-bignumber

It does seem unrelated to node-cbor (as ipld has it too). Seems bignumber has been having issues like this: https://github.com/MikeMcl/bignumber.js/issues/166 and MikeMcl/bignumber.js#199

which produces:

+ node dist/index.js
/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:4144
const MINUS_ONE = new bignumber(-1);
                  ^

TypeError: bignumber is not a constructor
    at Object.parcelRequire.1mQP.bignumber.js (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:4144:19)
    at newRequire (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:49:24)
    at localRequire (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:55:14)
    at Object.parcelRequire.b+YO.../vendor/binary-parse-stream (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:4268:16)
    at newRequire (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:49:24)
    at localRequire (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:55:14)
    at Object.parcelRequire.eVKc../utils (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:4921:17)
    at newRequire (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:49:24)
    at localRequire (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:55:14)
    at Object.parcelRequire.dsOm../commented (/Users/tobowers/code/minimal-fail-bignumber/cbor-bignumber/dist/index.js:6434:21)

@hildjj
Copy link
Owner

hildjj commented Jan 28, 2019

Based on your repro, I think that if I change to this it will work in both environments at the moment:

const bignumber = require('bignumber.js').BigNumber

@hildjj
Copy link
Owner

hildjj commented Jan 28, 2019

Yes, that seemed to work, both in node as well as in the parcel version (after I updated the version number to force whatever cache parcel was using to be refreshed). I'm going to commit this, and study the CI run carefully.

@tobowers
Copy link

There is also a change happening at bignumber: parcel-bundler/parcel#2581 (comment)

@hildjj
Copy link
Owner

hildjj commented Jan 28, 2019

Nod. With a clean CI run for node (https://travis-ci.org/hildjj/node-cbor/builds/485581442) I propose to do a release at this point so others can check if this fixes their issue, then carefully monitor the above thread for a resolution, carefully backing this out as needed when I take the next bignumber.js version. Any concerns @tobowers ?

And, btw, thank you SO much for the clean repro.

@tobowers
Copy link

No concerns from me. Thanks!

@hildjj
Copy link
Owner

hildjj commented Jan 28, 2019

Done. Look for cbor@4.1.5. Leaving this issue open for now until we decide if this is the final resolution.

@hildjj
Copy link
Owner

hildjj commented Aug 5, 2019

Seeing no further comments, let's mark this as done.

@hildjj hildjj closed this as completed Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants