connex icon indicating copy to clipboard operation
connex copied to clipboard

ReferenceError: self is not defined

Open sukhbirsingh1512 opened this issue 2 years ago • 1 comments

My code

import Connex from '@vechain/connex'

const connex = new Connex({ node: 'https://testnet.veblocks.net/', network: 'test' })

======Response======= eracomtechnologies@Eracoms-MacBook-Pro c9x % node index.mjs /Users/eracomtechnologies/Eracom/node_modules/@vechain/connex/dist/connex.js:10 })(self, function() { ^

ReferenceError: self is not defined at Object. (/Users/eracomtechnologies/Eracom/node_modules/@vechain/connex/dist/connex.js:10:4) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at ModuleWrap. (node:internal/modules/esm/translators:170:29) at ModuleJob.run (node:internal/modules/esm/module_job:198:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:385:24) at async loadESM (node:internal/process/esm_loader:88:5)

sukhbirsingh1512 avatar Jun 19 '22 10:06 sukhbirsingh1512

https://github.com/vechain/connex/tree/master/packages/connex#using-in-nodejs-environment

libotony avatar Jun 19 '22 14:06 libotony

https://github.com/vechain/connex/tree/master/packages/connex#using-in-nodejs-environment

I'm not able to import this lib into client Node code with ssr enabled. If possible, would be nice to add a shim so if the browser object is not defined than no error would be thrown immediately. The workaround is to conditionally/dynamically import the library, but that is not always possible, and seems like ideally the entry point would evaluate whether the required object even exists (and if it does not, nothing should be ran)

HIT2022 avatar Dec 27 '22 00:12 HIT2022