cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
callum Member
Member

External library only accessible with <any>window

Hello,

I'm sorry to ask such a common question... however this has been bugging me for hours! I'm doing all this in a brand new project so it's a clean slate.

I'd like to use the tinycolor JS library in my project. The only things I've done since creating the new project are:

1. Ran "npm install --save tinycolor2 @types/tinycolor2
2. Added "node_modules/@types/tinycolor2/index.d.ts" to the "files" section of tsconfig.json
3. Added "node_modules/tinycolor2/tinycolor.js" to the "externalJS" section of pbiviz.json
4. Added the line console.log(tinycolor("red")); console.log(true); at the top of the visual's update method.

 

However, this causes the update method to just stop executing after the first line (this was the reason for console.log(true), to pinpoint where it stops executing). Strangely, no error is logged or anything - but something is clearly going wrong to stop the rest of the method executing.

If I change tinycolor("red") to (<any>window).tinycolor("red") then it logs a tinycolor instance, followed by true... as desired.

This isn't expected behaviour, right?

 

I can get around this by adding let tinycolor = (<any>window).tinycolor; at the top of my visual's module, and then the first example works... but surely there's no way that's the intended method of doing this?

As I said, this is happening on a blank project, so you can copy my steps and see for yourself.

What am I doing wrong? I've followed everything in the guide here.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: External library only accessible with <any>window

@callum,

 

Based on my research, you could add statement below to tinycolor.js.

this.tinycolor = tinycolor;
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 REPLY 1
Community Support Team
Community Support Team

Re: External library only accessible with <any>window

@callum,

 

Based on my research, you could add statement below to tinycolor.js.

this.tinycolor = tinycolor;
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 127 members 1,548 guests
Please welcome our newest community members: