Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import/declare to work in Angular2 with Typescript? #1

Open
jackpunt opened this issue Mar 21, 2017 · 6 comments
Open

How to import/declare to work in Angular2 with Typescript? #1

jackpunt opened this issue Mar 21, 2017 · 6 comments

Comments

@jackpunt
Copy link

Do you have an example of how this can be imported when using Angular2 with Typescript?

Doing the simple: import "yuki-createjs";
Generates complaint from compiler: Cannot find name 'createjs'.

(amazingly, if I recompile a couple of times, it eventually is compiled and runs,
but I'm hoping it can be declared to compile the first time)

@JustinElst
Copy link

I have the same problem but after multiple recompiles it still fails..
"Cannot find namespace 'createjs'."
or
Module not found: Error: Can't resolve 'createjs' in '\app\src'

@limichange
Copy link
Member

Do you import it by webpack ?

@limichange
Copy link
Member

Can you give me a example ?

@jackpunt
Copy link
Author

I've tried various things; the simplest I have that mostly "works" is:
Presumably using webpack via angular:

% npm install yuki-createjs --save

In my package.json:
"dependencies": { ... "yuki-createjs": "0.0.3", ...}
in ./src/app/app.module.ts:
import 'yuki-createjs';
in ./src/index.html

<script src="node_modules/yuki-createjs/lib/easeljs-0.8.2.combined.js"></script>

I'm running: ng serve (the automatic recompilation)

When I save a .ts file, the compiler complains at every reference, one of:
... Cannot find name 'createjs'.)
... Cannot find namespace 'createjs'.)

After a couple of retries (retriggering ng serve compilation)
It looks happy, and it all runs;
(finding the createjs code via the <script> not from the Typescript import)

I'm new at this; and expect I'm missing something fundamental
Can you explain the RIGHT way to do this?

@jackpunt
Copy link
Author

jackpunt commented May 30, 2017

For the record: after upgrading Angular and Typescript to latest versions (4.1.3, 2.3.3)
using: import createjs from 'yuki-createjs';
seems to satisfy Typescript compiler.

Still trying to get 'ng serve' to find/load yuki-createjs,
hopefully there's some webpack incantation that will it it working.
(looking at CreateJS/EaselJS#713, but no joy yet)

@jackpunt
Copy link
Author

And now, webpack is happy!

The solution was to add module.exports to index.js:

require('./lib/easeljs-0.8.2.combined.js');
require('./lib/preloadjs-0.6.2.combined.js');
require('./lib/soundjs-0.6.2.combined.js');
require('./lib/tweenjs-0.6.2.combined.js');
module.exports = window.createjs;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants