How to import strophe using requirejs?

I am trying to use strophe.js with relay-starter-kit . I checked relay-starter-kit , added "strophe": "^1.2.2" to package.json and ran npm install .

I cannot find how to import strophe without errors. If I just try import Strophe from 'strophe'; I get errors that webpack cannot solve strophe-polyfill . I added a solution alias pointing to the main strophe.js file, but that didn't help (I just get the console message Uncaught ReferenceError: Strophe is not defined ).

There seems to be some weird modular system in the stanza (it mentions AMD on github, but I thought it meant I could just require , but apparently not). All the examples I've seen import into an HTML file and clutter up the global namespace. I need to use it from the inside out, so I don’t think it will work.

How to import strophe for use in my es6 files?

+4
source share
2 answers

Since I spent several hours of my life doing this, here is the answer:

  • Include strophe in the HTML file with:

  • Edit server.js to make webpack expose strophe as a static path with:

    app.use ('/ node_modules / strophe', express.static ('node_modules / strophe'));

  • The react component does not need to import strophe, as it is now available worldwide. Instead, just connect, for example:

    var connection = new Strophe.Connection ("ws: //" + server + ": 5280 / websocket /");

+4
source

try using import * as XMPP from strophe.js , then call

var connection = new XMPP.Strophe.Connection(BOSH_SERVICE) to connect the server

0
source

All Articles