2

I have a small problem. I'm developing a game using CraftyJS and I need to use Electron to run it, but Electron throws this error:

Uncaught TypeError: Crafty.scene is not a function
at Level1.js:4

Why does it do this? Here's the relevant code + markup:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>Overtime-game</title>
 </head>
 <body>
  <div id="game"></div>
  <script type='text/javascript' src='./node_modules/craftyjs/dist/crafty.js'></script>
  <script src='./Level1.js'>
  </script>
 </body>
</html>

JS:

//Relevant code:
Crafty.scene('main', function() {
Crafty.init(500,500, document.getElementById('game'));
// rest of Crafty.scene...
}
Crafty.scene('main') 
chazsolo
  • 7,873
  • 1
  • 20
  • 44
  • What does logging `Crafty` show you? – pushkin Dec 18 '18 at 19:55
  • @pushkin Nothing. It appears to be a problem with Electron, cause i can use CraftyJS using Beefy and Browserify just fine. – Gingka Akiyama Dec 19 '18 at 23:27
  • Nothing as in `undefined`, or you don't see any logs? If it were `undefined`, your error would be something like "cannot read property 'scene' of undefined", so I would suspect it's the latter. Try using breakpoints to examine what it's set to. Try requiring the npm module in your JS instead of using `script` – pushkin Dec 19 '18 at 23:32
  • @pushkin Do you mean `require` in the HTML page? cause it cant be used in HTML. if you mean the actual JS, the module is required: `var Crafty = require('craftyjs')` – Gingka Akiyama Dec 20 '18 at 01:02

1 Answers1

0

FIXED ON ELECTRON FORUMS:Apparently if you require a module in the file Electron will not look in node_modules. https://discuss.atom.io/t/solved-typeerror-crafty-scene-is-not-a-function/61273