0

電子アプリでは、 libp2p を main.ts にインポートするだけです:

const Libp2p = require('libp2p');

このエラーが発生します:

A JavaScript error occurred in the main process
Uncaught Exception:
ReferenceError: self is not defined
    at Object../node_modules/multihashing-async/src/sha.browser.js (/home/marco/webMatters/electronMatters/OnlyLibp2p
/.webpack/main/index.js:34203:16)
    at __webpack_require__ (/home/marco/webMatters/electronMatters/OnlyLibp2p/.webpack/main/index.js:21:30)
    at Object../node_modules/libp2p-crypto/src/keys/rsa-class.js (/home/marco/webMatters/electronMatters/OnlyLibp2p
/.webpack/main/index.js:19523:13)

tsconfig.json :

{
  "compilerOptions": {
    "jsx": "react",
    "allowJs": true,
    "target": "ES6",
    "module": "ESNext",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "noImplicitAny": false,
    "sourceMap": true,
    "baseUrl": ".",
    "outDir": "dist",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "paths": {
      "*": ["node_modules/*"],
      "@app/*": ["./src/app/*"],
      "@static/*": ["./src/static/*"],
      "@src/*": ["./src/*"]
    }
  },
  "include": ["src/**/*"]
}

devDependencies :

"@electron-forge/cli": "6.0.0-beta.53",
"@electron-forge/maker-deb": "6.0.0-beta.53",
"@electron-forge/maker-rpm": "6.0.0-beta.53",
"@electron-forge/maker-squirrel": "6.0.0-beta.53",
"@electron-forge/maker-zip": "6.0.0-beta.53",
"@electron-forge/plugin-webpack": "6.0.0-beta.53",
"electron": "^11.2.1",
"typescript": "^4.0.2",
"webpack": "4"

依存関係:

"libp2p": "^0.30.4",
"libp2p-kad-dht": "^0.20.6",
  • ノードのバージョン: v14.5.0
  • OS : Ubuntu 18.04.4 デスクトップ

これは、別の libp2p ライブラリをインポートするときにも発生することがわかりました。

//const Libp2p = require('libp2p');
const KadDHT = require('libp2p-kad-dht');

問題を解決するには?

4

1 に答える 1