sebamawa Posted November 22, 2016 Share Posted November 22, 2016 Friends, greetings to all. Return to Phaser after a while. I'm working with WebStorm and TypeScript. I have a problem with importing a class into a .ts (typescript) file: Import EnemySprite from './classes/EnemySprite'; Translated to javascript: Var EnemySprite_1 = require ( './ classes / EnemySprite'); The require () function is not recognized, so when I run the game I get the following message in the index.html: Uncaught ReferenceError: require is not defined Some help? Thank you! Link to comment Share on other sites More sharing options...
LuizOtavio Posted November 22, 2016 Share Posted November 22, 2016 hmmmm, im dev phaser with javascript, but, may i help you (I work with Ionic2 (angular2 + typescript)) when i have to use some lib from node_modules, i just put declare function require(name: string); among the imports. cheers Link to comment Share on other sites More sharing options...
sebamawa Posted November 22, 2016 Author Share Posted November 22, 2016 Thanks Luiz, The problem is that I do not know what library to import. What's more, I do not have the node_modules directory in the project. To add it to a Phaser project? Back time worked with javascript hard, but now Typescript feel more comfortable, but right now I'm a little lost. Link to comment Share on other sites More sharing options...
LuizOtavio Posted November 22, 2016 Share Posted November 22, 2016 Hmmm, 1. make sure have nodejs installed. 2. run in project folder $ npm install phaser --save 3. create a app.ts 3. put this in the first line: import {Phaser} from 'phaser/typescript/phaser'; 4. u ready to follow these steps: https://phaser.io/tutorials/how-to-use-phaser-with-typescript cheers sebamawa 1 Link to comment Share on other sites More sharing options...
sebamawa Posted November 22, 2016 Author Share Posted November 22, 2016 Thank you very much Luiz, I was not using npm to download the libraries of Pahser, I did it directly from the web. That tutorial had seen it. The problem is with the import of the require () function. If I can solve it I say it here, regards Link to comment Share on other sites More sharing options...
Recommended Posts