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 #41

Closed
metacoin opened this issue Mar 4, 2019 · 8 comments
Closed

TypeError: Bignumber is not a constructor #41

metacoin opened this issue Mar 4, 2019 · 8 comments

Comments

@metacoin
Copy link

metacoin commented Mar 4, 2019

When using borc in an electron webpack app, I am getting the error TypeError: Bignumber is not a constructor.

When inspecting Bignumber with console.log in constants.js, I noticed this:

┏ Electron -------------------
  Bignumber:  Object [Module] {
    BigNumber: [Getter],
    default:
     { [Function: BigNumber]
       clone: [Function: clone],
       ROUND_UP: 0,
       ROUND_DOWN: 1,
       ROUND_CEIL: 2,
       ROUND_FLOOR: 3,
       ROUND_HALF_UP: 4,
       ROUND_HALF_DOWN: 5,
       ROUND_HALF_EVEN: 6,
       ROUND_HALF_CEIL: 7,
       ROUND_HALF_FLOOR: 8,
       EUCLID: 9,
       set: [Function],
       config: [Function],
       isBigNumber: [Function],
       max: [Function],
       maximum: [Function],
       min: [Function],
       minimum: [Function],
       random: [Function],
       sum: [Function] } }
┗ ----------------------------

I changed this line:

const Bignumber = require('bignumber.js')

From this:

const Bignumber = require('bignumber.js')

to this:

const Bignumber = require('bignumber.js').default

I did the same thing here:

const constants = require('./constants')

I am pretty new to electron and webpack and not sure why I had to do this, but perhaps changing the code for compatibility would be good for others creating electron apps or using tools similar to webpack. Or, some guidance on how I can avoid these errors would be appreciated. Thanks!

@hugomrdias
Copy link

can you please confirm that all of versions bellow work in an electron enviroment ?

const Bignumber = require('bignumber.js').default
const {Bignumber} = require('bignumber.js')
const Bignumber = require('bignumber.js').BigNumber

@metacoin
Copy link
Author

metacoin commented Mar 4, 2019

const {Bignumber} = require('bignumber.js') Results in the same error as above:

┏ Electron -------------------

  A JavaScript error occurred in the main process
  Uncaught Exception:
  TypeError: Bignumber is not a constructor
      at eval (webpack-internal:///../../node_modules/borc/src/constants.js:62:19)

const Bignumber = require('bignumber.js').BigNumber does seem to work just as well as .default, no error reported

@hugomrdias
Copy link

do you know what MainFields order is used by webpack for electron ?
https://webpack.js.org/configuration/resolve/#resolvemainfields

@metacoin
Copy link
Author

metacoin commented Mar 6, 2019

I'm not sure what the default is. Right now, my webpack.config.js file is completely empty, if that helps. I will be looking more closely at this later on... will report back with any findings

@hugomrdias
Copy link

@olizilla can you help with this? Webpack with electron doesn't follow browser > module> main by default?

@elantion
Copy link

elantion commented Mar 11, 2019

I am facing the same issue in an almost brand new project. Using electron, vue-cli and ipfs-js. It's very easy to reproduce this issue.

  1. Install vue-cli: yarn global add @vue/cli.
  2. Create a project: vue create test.
  3. Add electron support: vue add electron-builder.
  4. Put test code in 'ready' event callback at background.js.
app.on('ready', async () => {
  if (isDevelopment && !process.env.IS_TEST) {
    // Install Vue Devtools
    try {
      await installVueDevtools()
    } catch (e) {
      console.error('Vue Devtools failed to install:', e.toString())
    }
  }
  createWindow();
  const ipfs = new IPFS;
  ipfs.on('ready', ()=>{
      console.log('ready');
      resolve(ipfs);
  });
})
  1. Run with yarn electron:serve.
  2. You can see a error like below:
App threw an error during load
TypeError: Bignumber is not a constructor
    at eval (webpack:///./node_modules/borc/src/constants.js?:62:19)
    at Object../node_modules/borc/src/constants.js (/Users/yinjames/Projects/lc-ipfs/dist_electron/index.js:1760:1)
    at __webpack_require__ (/Users/yinjames/Projects/lc-ipfs/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/borc/src/utils.js?:5:19)
    at Object../node_modules/borc/src/utils.js (/Users/yinjames/Projects/lc-ipfs/dist_electron/index.js:1855:1)
    at __webpack_require__ (/Users/yinjames/Projects/lc-ipfs/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/borc/src/decoder.js?:7:15)
    at Object../node_modules/borc/src/decoder.js (/Users/yinjames/Projects/lc-ipfs/dist_electron/index.js:1783:1)
    at __webpack_require__ (/Users/yinjames/Projects/lc-ipfs/dist_electron/index.js:20:30)
    at eval (webpack:///./node_modules/borc/src/diagnose.js?:3:17)

@haywirez
Copy link

haywirez commented Mar 31, 2019

Also encountering this issue, part of an IPFS-related package...seems to affect webpack in general

@ishan-ghorela
Copy link

hi I am still facing this issue

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

5 participants