Jump to content

Unexpected token < phaser.js:1


Benagin
 Share

Recommended Posts

Hello,

I am trying to do something very basic with phaser. I have a basic index.html file and I'm just trying to load the phaser.js file. The html correctly displays but in the console I get unexpected token <     phaser.js:1. Is this a problem? Is is avoidable? I have other components (menu/game) that I am trying to add but this occurs without them anyway. I have the Phaser 2.6.2 from their website.

<!DOCYTPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Survive or Die</title>

  <script src="js/phaser.js"></script>
</head>

<body>
test
</body>
</html>

Here is my index.html. "test" displays properly but when I inspect and look at the console I get this error. I get the same error when I try to add another script ("js/main.js").

Also here is my server, that might be causing the problems.

var http = require('http');
    fs = require('fs');
    url = require('url');

// Create server
// The function as argument, defines what happens with each request and
// response from the server
http.createServer(function(request, response) {
  var pathname = url.parse(request.url).pathname;
  console.log("Request for " + pathname + " received.");

  // In this case we are sending our index.html file to the page
  fs.readFile('../index.html', function(err, data) {
    response.writeHead(200, {'Content-Type': 'text/html', 'Content-Length': data.length});
    response.write(data);
    response.end();
  });
}).listen(55100);

console.log("Listening to server on 55100...")

Thanks for any help.

Link to comment
Share on other sites

The html looks fine so try and debug the server. Put a console.log('test') at the start of the server javascript. I do notice that you are declaring the variables slightly wrong but not to the point that should throw the server

var http = require('http'),
    fs = require('fs'),
    url = require('url');

// or

var http = require('http');
var fs = require('fs');
var url = require('url');

Is your node server correctly set up?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...