3

I am attempting to incorporate createJS into a typescript project (a powerbi visual) that I am building.

I have done the following:

1) Installed createJS and typings file using:

npm install createjs --save and npm install --save @types/createjs

2) Added this line to the the externalJS array in pbiviz.json : "node_modules/createjs/builds/1.0.0/createjs.min.js"

3) Added the path to the typings file to the files array in my tsconfig.ts file: "node_modules/@types/createjs/index.d.ts".

Something didn't go right, I'm seeing the following error in my console: Error Trace

This was without actually calling the namespace in my code, if I attempt to use the namespace then it simply breaks my code without any warnings. My IDE's auto-suggest offers createjsimplying to me that it was imported properly but still something isn't right.

I think its related to this thread but I don't understand how to implement the solution it typescript. Can anyone help?

My project structure: structure

ClimbingTheCurve
  • 323
  • 2
  • 14

2 Answers2

2

It appears that the issue is an internal issue. I found a solution that I will not pretend to fully understand.

Starting from scratch, instead of installing the createjs package with the --save option I ran

npm install createjs-module --save and npm install --save @types/createjs

which is apparently a webpack.

After this I "node_modules/createjs-module/createjs.js" in to my externalJS array, as well as the appropriate typings file to my tsconfig.json.

Credit to tsveti_iko

see also:

this

Brian
  • 6,910
  • 8
  • 44
  • 82
ClimbingTheCurve
  • 323
  • 2
  • 14
  • 1
    Could you please be so kind and *not* post the command `npm install createjs --save` just after the world "install" and in such a way that it is easy to copy? Because I totally over-read the "instead". I know that we should all carefully read but it is so easy to miss. It is just too inviting to just copy paste a command if it is written in such a way. – not_a_bot_no_really_82353 Nov 27 '20 at 21:41
0

There are 2 methods to import createjs(not createjs specific)

This is what I use in my ts classes. For this you have to set compiler options module to system in tsconfig.json. This is what I use. I seems it's not the recommended one. It like an import statement(or maybe more like an include script)

tsconfig.json:

{
    "compilerOptions": {
        "module": "system",

.ts files using createjs:

/// <reference path="../lib/createjs.d.ts"/>

The other method is to use import statements along with commonjs. This is the recommended one. I was not able to make it work but didn't try too much because the first method is working.

https://www.typescriptlang.org/docs/handbook/compiler-options.html