TypeError: Crafty.scene is not a function

111 Views Asked by At

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') 
1

There are 1 best solutions below

0
Gingka Akiyama On

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