is-ipfs icon indicating copy to clipboard operation
is-ipfs copied to clipboard

The line const i18n = require('i18next') causes ReferenceError: self is not defined

Open raphael10-collab opened this issue 4 years ago • 2 comments

In an electron app this line :

const i18n = require('i18next');

produces this error message:

 yarn start
yarn run v1.22.5
$ cross-env NODE_ENV=development electron-forge start
✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies
✔ Compiling Main Process Code
✔ Launch Dev Servers
⠦ Compiling Preload ScriptsIssues checking in progress...
⠦ Compiling Preload ScriptsIssues checking in progress...
✔ Compiling Preload Scripts
✔ Launching Application


Webpack Output Available: http://localhost:9000

Issues checking in progress...
2021-01-25T09:55:20.639Z info: [meta] logs can be found on /home/marco/.config/IPFSbase
App threw an error during load
ReferenceError: self is not defined
    at Object../node_modules/iso-url/src/url-browser.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack
/main/index.js:44404:21)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
    at Object../node_modules/iso-url/index.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack
/main/index.js:44342:5)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
    at Object../node_modules/is-ipfs/src/index.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack
/main/index.js:43618:17)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
    at Object../src/download-cid.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:76484:16)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
    at Module../src/main.ts (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:76851:26)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
A JavaScript error occurred in the main process
Uncaught Exception:
ReferenceError: self is not defined
    at Object../node_modules/iso-url/src/url-browser.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack    
/main/index.js:44404:21)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
   at Object../node_modules/iso-url/index.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack
/main/index.js:44342:5)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
    at Object../node_modules/is-ipfs/src/index.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack
/main/index.js:43618:17)
   at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
   at Object../src/download-cid.js (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:76484:16)
  at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
  at Module../src/main.ts (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:76851:26)
  at __webpack_require__ (/home/marco/webMatters/electronMatters/IPFSbase/.webpack/main/index.js:21:30)
webpack built 9380dd8a3c27d177f76b in 4809ms

in package.json :

devDependencies:
  "ipfs-or-gateway": "^2.1.0",
  "electron": "^10.1.2",

dependencies:
    "ipfs": "^0.53.1",
    "ipfs-http-client": "^48.2.0",
    "ipfsd-ctl": "^7.2.0",
    "is-ipfs": "^2.0.0",

Other info:

  • node version: v14.5.0
  • O.S. : Ubuntu 18.04.4.Desktop

How to solve the problem?

raphael10-collab avatar Jan 25 '21 10:01 raphael10-collab

@hugomrdias does this issue with iso-url in Electron look familiar?

lidel avatar Feb 20 '21 01:02 lidel

This should not happen, we have tests for Electron. This is probably a webpack config issue, @raphael10-collab you must be bundling with target browser or renderer but running the code in the main thread. Please double check your config.

hugomrdias avatar Feb 22 '21 15:02 hugomrdias

This module has been refactored and is now ESM only so require can't be used to load it.

Please open a new issue if you're still having problems.

achingbrain avatar Feb 06 '24 16:02 achingbrain