Cannot use SIP.js in ES6 module

1,572 views
Skip to first unread message

este...@gmail.com

unread,
Jun 6, 2019, 3:32:21 PM6/6/19
to SIP.js
Hi people, I'm newbie in web development, webRTC and SIPJS. I have a ES6 module that import sip.js and trying in different ways I have this error:

sip.js:46 Uncaught TypeError: Cannot set property 'SIP' of undefined
at webpackUniversalModuleDefinition (sip.js:46)
at sip.js:47
webpackUniversalModuleDefinition @ sip.js:46
(anonymous) @ sip.js:47

Any help will be appreciated.

Thanks in advance.

James Criscuolo

unread,
Jun 6, 2019, 3:34:50 PM6/6/19
to SIP.js
How are you attempting to import SIP.js? Using "import" or "require" should work, or you can add the bundle in a script, but at this point that way is unlikely.

Esteban Martin

unread,
Jun 6, 2019, 4:14:47 PM6/6/19
to SIP.js
I'm using:

import * as SIP from '../node_modules/sip.js/dist/sip.js'


but I tried with:

import * as SIP from './sip.js'

putting the sip.js file from the dist folder in the same js folder of my source code. I've also tried with

import * as SIP from '../node_modules/sip.js'

I'm specifying node_modules folder because I'm testing, then I' make a build with rollup.js.

James Criscuolo

unread,
Jun 6, 2019, 4:29:49 PM6/6/19
to SIP.js
Are you doing this with other node modules? I tried 

import * as SIP from "sip.js";

and it works fine. I am not familiar with rollup, but having to use relative routes sounds like an unnecessary step. If you have to use them, you can also try "(path to node_modules)/sip.js/lib/index.js". I would anticipate the other imports would lead to a different error though.

Once you get this working, I would recommend against using `import *`, you can just `import { UA } from "sip.js".

Esteban Martin

unread,
Jun 6, 2019, 5:23:05 PM6/6/19
to SIP.js
I tried

import * as SIP from './sip.js'

and the I have the same error.

and I tried

import {UA} from './sip.js'

and the error is 

(index):1 Uncaught SyntaxError: The requested module './sip.js' does not provide an export named 'UA'

in both cases I used the sip.js file from the dist folder.

Thanks.

James Criscuolo

unread,
Jun 6, 2019, 6:08:11 PM6/6/19
to SIP.js
I'm not sure why you include the "./", I'd try removing that. And I'd also say to use "lib/index.js" instead of the dist folder.

Esteban Martin

unread,
Jun 7, 2019, 12:07:56 AM6/7/19
to SIP.js
I use ./ because otherwise the this error is raised by Chrome:

Uncaught TypeError: Failed to resolve module specifier "sip.js". Relative references must start with either "/", "./", or "../".

This error is very similar to this topic in StackOverflow.

If I import with

import * as SIP from '../node_modules/sip.js/lib/index.js'

this error is raised by Chrome:

index.js:2 Uncaught ReferenceError: exports is not defined
    at index
.js:2
(anonymous) @ index.js:2


I want import sip.js, from the dist folder without webpack neither other building tool, in a ES6 module, is this possible ?

I'm using 0.13.6 version.

Thank you very much for your quick replies.

James Criscuolo

unread,
Jun 7, 2019, 10:24:13 AM6/7/19
to SIP.js
I think your best bet is to load the dist bundle via a script tag, then just use the SIP variable. To expand further, using rollup for your development build may be the easiest choice, but if you have other libraries that work in this fashion I'd be curious to know which and see if I can reverse engineer it.

Esteban Martin

unread,
Jun 7, 2019, 10:43:47 AM6/7/19
to SIP.js
Understood, sip.js cannot be imported from a ES6 module, always must be imported in html page through script tag.

For curiosity, why this limitation ?

Thanks.

James Criscuolo

unread,
Jun 7, 2019, 10:52:59 AM6/7/19
to SIP.js
Anecdotally, I would say the way you are attempting to use the library is quite uncommon. Most development processes now have some preprocessing (bundling/transpiling), and in those cases SIP.js is supported as an es6 module.

I'll repeat this again, if you can show me a library that works as you expect I will try to make it doable, but I don't believe this is typically something people run into. It's not common to make changes for your dev environment, then undo them all for your prod environment, it's just not scalable.

Esteban Martin

unread,
Jun 7, 2019, 11:09:27 AM6/7/19
to SIP.js
Ok, you say that if with the installed sip.js with npm and I make a build of my application then the  imported sip.js from a ES6 module works ?

James Criscuolo

unread,
Jun 7, 2019, 11:13:34 AM6/7/19
to SIP.js
If "make a build" means some compilation, then yes. I would like to add (mostly for anyone who stumbles upon this) that while the script tag form of including sip.js is still valid, it's mostly a backwards-compatibility type of release and shouldn't be necessary in modern builds.

Esteban Martin

unread,
Jun 7, 2019, 11:28:45 AM6/7/19
to SIP.js
"Make a build" means make a bundle (my final idea) of my application, in other words, if I want make a quickly test I must to use with script tag in html page. My mistake was to believe that referencing to node_modules or using sip.js from dist folder was enough.

Thanks.
Reply all
Reply to author
Forward
0 new messages