ftdeveloper
ftdeveloper

Reputation: 1093

Invalid indentation. Jade template

I know i can use tabs or spaces but not both. But i could not find where is the invalid indentation. Tried different variation. But I did not succeed. I got and exception after added

- if (error)
p= error

So my code is shown below:

!!!
html
head
    title= title
    link(rel='stylesheet', href='/stylesheets/#{stylesheet}.css')
    link(rel='stylesheet', href='/stylesheets/bootstrap.min.css')
body
    .container
        .row
            .col-md-4
            .col-md-4
                .well
                    - if (error)
                        p= error
                    form(role='form',action='sessions', method='post')
                        .form-group
                            label(for='Email') Eposta Adresi
                            input#Email.form-control(type='email',name='user[email]',placeholder='E-posta adresi')
                        .form-group
                            label(for='Password') Şifre
                            input#Password.form-control(type='password',name='user[password]', placeholder='Şifre')
                        button.btn.btn-default(type='submit') Giriş

    script(type='text/javascript', src='/javascripts/jquery-1.10.2.min.js')
    script(type='text/javascript', src='/javascripts/bootstrap.min.js')

Full Exception:

12| .well
13| - if (error)
> 14| p= error
15| form(role='form',action='sessions', method='post')
16| .form-group
17| label(for='Email') Eposta Adresi
Invalid indentation, you can use tabs or spaces but not both
at Object.Lexer.indent (C:\Nodejs\NodejsBlog\node_modules\jade\lib\lexer.js:691:15)
at Object.Lexer.next (C:\Nodejs\NodejsBlog\node_modules\jade\lib\lexer.js:789:15)
at Object.Lexer.lookahead (C:\Nodejs\NodejsBlog\node_modules\jade\lib\lexer.js:122:46)
at Object.Parser.lookahead     (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:116:23)
at Object.Parser.parseCode   (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:311:17)
at Object.Parser.parseExpr (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:225:21)
at Object.Parser.block (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:593:25)
at Object.Parser.tag (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:722:26)
at Object.Parser.parseTag (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:625:17)
at Object.Parser.parseExpr (C:\Nodejs\NodejsBlog\node_modules\jade\lib\parser.js:199:21)

Need advise.

Upvotes: 2

Views: 9344

Answers (3)

Paulson
Paulson

Reputation: 1

You can use Sublime Text editor to fix this:

  1. open the code in a sublime text editor
  2. click on views
  3. click on indentation
  4. finally click on convert indentation to space

Upvotes: 0

Jenna Leaf
Jenna Leaf

Reputation: 2452

You can also use Notepad++ to reveal the tabs and change them to spaces to correct your indentation problem.

I have node/npm message telling me that my jade engine's Parser and Lexer do not like my layout.jade code due to my inconsistency of indentation using both spaces and tabs starting from line#8. And that error is thrown by both Lexer and Parser objects (in lexer.js and parser.js respectively). So I opened up the file of problem - i.e., layout.jade and corrected the indentations. Here's the npm error msg I got in the beginning:

<pre>
Error: C:\Users\tester_Arch_GitHub\loc8r2mvc\app_server\views\layout.jade:8
   6|     title= title
   7|     link(rel='stylesheet', href='/bootstrap/css/amelia.bootstrap.css')
 > 8| link(rel='stylesheet', href='/stylesheets/style.css')
   9|   body
   10|     block content
   11|

Invalid indentation, you can use tabs or spaces but not both
   at Object.Lexer.indent (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\lexer.js:790:15)
   at Object.Lexer.next (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\lexer.js:941:15)
   at Object.Lexer.lookahead (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\lexer.js:113:46)
   at Parser.lookahead (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:102:23)
   at Parser.peek (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:79:17)
   at Parser.tag (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:773:22)
   at Parser.parseTag (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:759:17)
   at Parser.parseExpr (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:211:21)
   at Parser.block (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:729:25)
   at Parser.tag (C:\Users\tester_Arch_GitHub\loc8r2mvc\node_modules\jade\lib\parser.js:838:24)
</pre>

So I used my plain old editor Notepad++ : under Settings/Preferrences/Tab Setting/Javascript --> choose replace by space. OR . you just move your cursor using your arrow key to each line and simply detect the tabs and replace them with spaces! Do a refresh on the URL. You will see the indentation problem goes away!

Upvotes: 1

robertklep
robertklep

Reputation: 203304

This is what vim shows me with :set list:

▸ ▸ ▸ ▸ .col-md-4¬
▸ ▸ ▸ ▸ .col-md-4¬
▸ ▸ ▸ ▸ ▸ .well¬
▸ ▸ ▸ ▸ ▸ ▸ - if (error)¬
    ▸ ▸ ▸ ▸ ▸   ▸ p= error¬
▸ ▸ ▸ ▸ ▸ ▸ form(role='form',action='sessions', method='post')¬

(the triangles are tabs)

So you are mixing tabs and spaces on the offending line.

Upvotes: 8

Related Questions