Closed metacoin closed 5 years ago
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
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
do you know what MainFields
order is used by webpack for electron ?
https://webpack.js.org/configuration/resolve/#resolvemainfields
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
@olizilla can you help with this? Webpack with electron doesn't follow browser > module> main by default?
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.
yarn global add @vue/cli
.vue create test
.vue add electron-builder
.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);
});
})
yarn electron:serve
.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)
Also encountering this issue, part of an IPFS-related package...seems to affect webpack in general
hi I am still facing this issue
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 inconstants.js
, I noticed this:I changed this line: https://github.com/dignifiedquire/borc/blob/b14a3176cc2851185320c33ccaa0020746beacab/src/constants.js#L3
From this:
to this:
I did the same thing here: https://github.com/dignifiedquire/borc/blob/b14a3176cc2851185320c33ccaa0020746beacab/src/encoder.js#L7
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!