Using JavaScript BalenaSDK in Angular 8 (webpack)

Hi guys.
We are trying to use JS BalenaSDK to retrieve devices information. We need to use the SDK (rather than balena cloud directly) because we must merge informations provided from Balena with some local databases in our company. We need to display and manage data from BalenaSDK in an Angular 8 project.

The problem we are facing is the following: when launching the Angular app (with ng serve) we get a lot (like 30 or 40) errors. They all seem syntax errors, like the following:

ERROR in ../node_modules/balena-sdk/es2015/index.d.ts:2:13 - error TS1005: '=' expected.

2 import type { Pine as PineBase, PineStrict as PineStrictBase } from '../typings/balena-pine';
              ~
../node_modules/balena-sdk/es2015/index.d.ts:2:69 - error TS1005: ';' expected.

2 import type { Pine as PineBase, PineStrict as PineStrictBase } from '../typings/balena-pine';
                                                                      ~~~~~~~~~~~~~~~~~~~~~~~~
../node_modules/balena-sdk/es2015/index.d.ts:3:13 - error TS1005: '=' expected.

3 import type { BalenaRequest, Interceptor } from '../typings/balena-request';
              ~
../node_modules/balena-sdk/es2015/index.d.ts:3:49 - error TS1005: ';' expected.

3 import type { BalenaRequest, Interceptor } from '../typings/balena-request';
                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
../node_modules/balena-sdk/es2015/index.d.ts:4:13 - error TS1005: '=' expected.

We installed the SDK using npm install balena-sdk

I don’t think this error is Angular-specific, I think it probably is related to Webpack or TypeScript transpiler, but I have no clue on how to solve it.

The project is using TypeScript 3.5.3.

Our IDE (Visual Studio) doesn’t show any syntax error and shows data types correctly while coding.

Do you have any idea? Thank you!

Ok after some trial and error we discovered it was a problem with TypeScript 3.5 which seemed to be incompatible with the latest version of BalenaSDK. After upgrading to TypeScript 3.8 (which required an Angular update to version 9+) everything is working fine.

I wasn’t able to find on Github and on official documentation the minimum compatible TypeScript version, maybe it could be added? I know BalenaSDK is a Javascript library, but the line separating JS and TS is ofter blurry.

Hey Andrea,
Sorry that you had to go through with this. We work mostly with TS so I can understand your pain when compatibility issues like this happen for packages. AFAIK we don’t specifically test TS version compatibility or the reason why we don’t mention the TS version we support (or don’t support). I know some packages definitely provide warnings when you use TS versions that are not supported by said packages (example: Typedoc). Thank you for your feedback, we will definitely work on this!

1 Like

I also created an issue to track this: Specify supported Typescript versions for balena-sdk · Issue #1142 · balena-io/balena-sdk · GitHub