Home » Nodejs » Jade unexpected token “indent”

Jade unexpected token “indent”

Posted by: admin November 29, 2017 Leave a comment

Questions:

I am trying to run sparkleshare-dashboard which is an open source. Up till now i got many errors because i have no fimiliarity with the technology used in it. So, this time when i run app.js from command prompt using node command i got this error.

Warning: missing space before text for line 20 of jade file "D:\Imports\sparkles
    hare-dashboard/views/createFirstUser.jade"
    Error: D:\Imports\sparkleshare-dashboard/views/createFirstUser.jade:21
        19|   script(type="text/javascript")
        20|     $("#login").focus(function()

 {
  > 21|       $("#loginlabel").fadeOut();
    22|     });
    23|     $("#login").blur(function() {
    24|       if ($("#login").val().length == 0) {

unexpected token "indent"
    at Parser.parseExpr (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib
\parser.js:229:15)
    at Parser.block (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib\par
ser.js:689:25)
    at Parser.tag (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib\parse
r.js:806:26)
    at Parser.parseTag (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib\
parser.js:719:17)
    at Parser.parseExpr (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib
\parser.js:188:21)
    at Parser.block (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib\par
ser.js:689:25)
    at Parser.tag (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib\parse
r.js:806:26)
    at Parser.parseTag (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib\
parser.js:719:17)
    at Parser.parseExpr (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib
\parser.js:188:21)
    at Parser.parseExpr (D:\Imports\sparkleshare-dashboard\node_modules\jade\lib
\parser.js:227:21)
Answers:

You have a syntax error in your code, you simply missed a dot and this causes another error, see my fixed example at the end:

script(type="text/javascript")
    $("#login").focus(function(){
      $("#loginlabel").fadeOut();
    });

will prompt an Unexpected token "indent" error. Because Jade sees your $("#loginlabel").fadeOut(); as another line of code and this line has, for Jade, a wrong indentation.

Generally this "indent" errors are always pointing, in the end, to a wrong indentation.

So to get rid of this error, just add a dot at the end of the script tag and make clear thats a hole part oft none Jade code is following, like:

script(type="text/javascript").
    $("#login").focus(function() {
    $("#loginlabel").fadeOut();
    });

This (see that dot) will give you the following HTML output:

<script type="text/javascript">
  $("#login").focus(function() {
    $("#loginlabel").fadeOut();
  });
</script>

Questions:
Answers:

The correct syntax is:

script.
  document.location = "https://google.com"