{"action":"closed","issue":{"url":"https://api.github.com/repos/uport-project/uport-connect/issues/243","repository_url":"https://api.github.com/repos/uport-project/uport-connect","labels_url":"https://api.github.com/repos/uport-project/uport-connect/issues/243/labels{/name}","comments_url":"https://api.github.com/repos/uport-project/uport-connect/issues/243/comments","events_url":"https://api.github.com/repos/uport-project/uport-connect/issues/243/events","html_url":"https://github.com/uport-project/uport-connect/issues/243","id":384630896,"node_id":"MDU6SXNzdWUzODQ2MzA4OTY=","number":243,"title":"Including webpacked output file via RequireJS fails to load PubSub module","user":{"login":"MidnightLightning","id":250250,"node_id":"MDQ6VXNlcjI1MDI1MA==","avatar_url":"https://avatars3.githubusercontent.com/u/250250?v=4","gravatar_id":"","url":"https://api.github.com/users/MidnightLightning","html_url":"https://github.com/MidnightLightning","followers_url":"https://api.github.com/users/MidnightLightning/followers","following_url":"https://api.github.com/users/MidnightLightning/following{/other_user}","gists_url":"https://api.github.com/users/MidnightLightning/gists{/gist_id}","starred_url":"https://api.github.com/users/MidnightLightning/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MidnightLightning/subscriptions","organizations_url":"https://api.github.com/users/MidnightLightning/orgs","repos_url":"https://api.github.com/users/MidnightLightning/repos","events_url":"https://api.github.com/users/MidnightLightning/events{/privacy}","received_events_url":"https://api.github.com/users/MidnightLightning/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-27T05:32:49Z","updated_at":"2018-12-07T20:35:40Z","closed_at":"2018-12-07T20:35:40Z","author_association":"NONE","body":"When using the distributed files through unpkg or compiling myself from source, I'm encountering an error getting the basic infrastructure working. I'm using RequireJS as my loader, with the following setup:\r\n\r\n```js\r\nrequirejs.config({\r\n  paths: {\r\n    'uportconnect': '//unpkg.com/uport-connect@1.0.0/dist/uport-connect'\r\n  }\r\n});\r\n\r\ndefine(function(require) {\r\n  'use strict';\r\n  var Connect = require('uportconnect');\r\n\r\n  var uport = new Connect('My Test App', { network: 'rinkeby' });\r\n  uport.requestDisclosure();\r\n  uport.onResponse('disclosureReq').then(res => {\r\n    var did = res.payload.did;\r\n    debugger;\r\n  });\r\n});\r\n```\r\n\r\nThe error is in the console, I see\r\n\r\n```\r\nUncaught (in promise) TypeError: _this3.PubSub.subscribe is not a function\r\n    at eval (Connect.js:6127)\r\n    at new Promise (<anonymous>)\r\n    at Connect.onResponse (Connect.js:6123)\r\n```\r\n\r\nin the console when the request is fired off, and \r\n\r\n```\r\nUncaught (in promise) TypeError: _this5.PubSub.publish is not a function\r\n    at eval (Connect.js:6254)\r\n```\r\n\r\nAfter I scan the QR code with the uPort app. The QR code on the website goes away, but the response debugger never gets hit.\r\n\r\nThis happens with the 1.0.0 and the 1.0.2 versions, both with the minified and non-minified versions on unpkg.\r\n\r\n---\r\n\r\nDigging more through this, it seems to be an issue with Webpack interacting with RequireJS for this project. RequireJS defines a `define()` and `require()` function that are meant for top-level module loading on-demand.\r\n\r\nAs part of the bundling process, Webpack replaces calls to `require()` with `__webpack_require__()`, which is good, and doesn't conflict with RequireJS'. However, it does not replace calls to `define()` with something else. In my application that's using RequireJS, the `pubsub-js` library that uPort is depending on calls `define()` explicitly and it's resolving to the RequireJS one, resulting in the Webpack module getting an empty object returned rather than the library object.\r\n\r\nThe solution to this is to shim the inclusion of that module to make it believe that `define` isn't a function, so it won't go down that logic trail. This seems to be the situation laid out in \"Tip #4\" in this article: https://medium.com/webpack/how-to-cope-with-broken-modules-in-webpack-4c0427fb23a (their suggestion is to use `imports-loader` and `exports-loader` to make the module export as a global variable, and then capture it)."}}
{"actor":{"display_login":"rmw2"}}