Skip to content
This repository has been archived by the owner on Mar 24, 2019. It is now read-only.

How to use this with nodejs? #3

Closed
piranha771 opened this issue Dec 4, 2015 · 2 comments
Closed

How to use this with nodejs? #3

piranha771 opened this issue Dec 4, 2015 · 2 comments

Comments

@piranha771
Copy link

I've, downloaded the p2 package via npm for nodejs.
How do I use the p2.d.ts with this package? Can you give an example?

/// <reference path='../typings/p2/p2.d.ts' />
import p2 = require('p2'); // <---- this causes 'p2 module not found' error (TS2307)
import GameObject = require('./GameObjectNew');
import player = require('./asset/PlayerNew');


class Game {

    gameObjects: GameObject[] = [];
    players: GameObject[] = [];
    sessionEvents = [];
    globalEvents = [];

    world: p2.World = new p2.World({
        gravity: [0.0, 0.0]
    });

.........
@clark-stevenson
Copy link
Owner

I personally cannot speak for require as I use SystemJS (but even then, I do not use SystemJS with p2).

I would guess that the following line may need to be added to at the bottom of the p2.d.ts file. Can you try it?

declare module 'p2' {
export = p2;
}

That might fix your p2 error. If you are using ES6 or a new version of typescript, I think it needs to be

declare module 'p2' {
export default p2;
}

But a lot of this is guesswork. All my projects still use the trusty script tag apart from one project which I am working on in my free time with SystemJS.... I hope someone else may be able to chip in if this does not work.

@piranha771
Copy link
Author

Thanks a lot, that works like a charm!

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

No branches or pull requests

2 participants