Compiling SIP.js with TypeScript?

489 views
Skip to first unread message

Slavik Bialik

unread,
Feb 8, 2021, 4:23:31 AM2/8/21
to SIP.js
Hi,
It is my first time that I want to try and change some source code and compile it and use it my main project that is using SIP.js.
I am compiling it on Windows (although using Cygwin as a terminal, as I see that some commands in the npm run commands are Linux commands).

I am doing:
  1. npm install
  2. npm build
everything compiles, but...
When I am trying to use the compiled project in my TypeScript project (not by using the compiled "sip.min.js" file, but using TypeScript imports) I am getting lots of errors from this kind:
Severity Code Description Project File Line Suppression State
Error TS2322 (TS) Type 'Timeout' is not assignable to type 'number'. D:\DEV\client (tsconfig or jsconfig project) D:\DEV\client\sipjs\src\api\invitation.ts 99 Active
Error TS2322 (TS) Type 'Timeout' is not assignable to type 'number'. D:\DEV\client (tsconfig or jsconfig project) D:\DEV\client\sipjs\src\api\invitation.ts 116 Active
Error TS2322 (TS) Type 'Timeout' is not assignable to type 'number'. D:\DEV\client (tsconfig or jsconfig project) D:\DEV\client\sipjs\src\api\publisher.ts 231 Active
Error TS2322 (TS) Type 'Timeout' is not assignable to type 'number'. D:\DEV\client (tsconfig or jsconfig project) D:\DEV\client\sipjs\src\api\registerer.ts 677 Active

I am having the above error for all of the objects in API.

Can you please suggest me how should I do it correctly?

Thanks!

James Criscuolo

unread,
Feb 8, 2021, 9:07:37 AM2/8/21
to SIP.js
That output implies you are trying to compile the code again in your project. I suspect you have types/node installed, which would lead to those issues I believe. Two important things:

- The compiled output is in `lib`, not `src`.
- Your tsconfig is likely attempting to compile our folder when you don't want it to. There are rules (like exclude) to deal with that not happening.

Lastly, if you are using npm and have no customizations to our library, installing sip.js as a dependency will get around this (npm install sip.js).

James

Slavik Bialik

unread,
Feb 8, 2021, 9:43:55 AM2/8/21
to SIP.js
Thanks James!
Currently, I have a TypeScript project that is using NPM. My package.json file has the sip.js as a dependency. So when I am doing "npm install" on my whole project it downloads also the SIP.js library.
I tried to compile it from the downloaded, but seems like I cannot because when it downloads the sip.js library, it has no "src" folder so nothing to compile as it is already compiled.
So that's why I just cloned the SIP.js source code separately, compiled it, and I just changed (for test purpose) my import paths (in my TS code) to point the new folder and not the SIP.js that is auto downloaded into "npm_modules" folder.
Anyway, I am not sure what I am missing here. 

James Criscuolo

unread,
Feb 8, 2021, 9:54:00 AM2/8/21
to SIP.js
We don't deliver the src folder with the npm package on purpose, as there is no need for you to recompile, so it would just be wasted space. Your tsconfig should not be attempting to compile anything in your npm_modules folder, try deleting the sip.js with source and adding this:
    "exclude": [
      "npm_modules"
    ]

Most libraries are delivered in the same fashion, so adding this should not blow up the rest of your build.

Slavik Bialik

unread,
Feb 8, 2021, 10:57:46 AM2/8/21
to SIP.js
OK,
So I added the "exclude" part into my tsconfig.json of my main project.
Now it looks like this:
{
  "compilerOptions": {
    "allowJs": true,
    "target": "es2015",
    "module": "CommonJS",
    "strict": true,
    "esModuleInterop": true,
    "importHelpers": true,
    "sourceMap": true,
    "lib": [
      "es2015",
      "DOM"
    ]
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "npm_modules"
  ]
}

But then I do not understand why you wrote "...try deleting the sip.js with source". As this is the separate folder where I cloned the project and successfully compiled SIP.js where I also want to make my minor changes in the library.
Or you meant deleting the "sip.js" folder in "npm_modules"?
Maybe something in the tsconfig.json interrupting with what I am trying to achieve here? Because this is kind of a new to me, and I don't really understand what all of the parameters means.

Thanks again! And sorry for the noobish questions :)

James Criscuolo

unread,
Feb 8, 2021, 11:15:47 AM2/8/21
to SIP.js
In that case, you want to remove the dependency, and add the sip.js with source folder to your excludes.

Slavik Bialik

unread,
Feb 9, 2021, 3:43:30 AM2/9/21
to SIP.js
Hi James,
I did as you said, but still getting the same errors.
Also tried to change the dependency in package.json file to be local, like this:
"sip.js": "file:./sipjs/"

And still the same issue.

Maybe something with my tsconfig.json file is not compatible? (Besides the 'exclude' that I added)

Thanks!

Slavik Bialik

unread,
Feb 9, 2021, 4:07:32 AM2/9/21
to SIP.js
OK! It is working now!
Maybe I do not fully understand the point of "exclude" in tsconfig.json, but after adding the path to the source folder also in the "exclude" array and doing "npm install" again in my main project, the errors gone.

Thanks James!

Reply all
Reply to author
Forward
0 new messages