Unexpected token "indent" when using Pug templates

peterHasemann

I have a simple application that should output a small content. I use NodeJs, Express and Pug.

const pug = require('pug');
const express = require('express');
const app = express();

const indexFile = 'index'; // the file to load

app.set('view engine', 'pug'); // use pug

app.get('/', function (req, res) {
  res.render(indexFile, {content: 7}); // load the file and set the variable to 7
});

app.listen(8888, function () {
  console.log('Server running on port 8888');
});

And my Pug file / HTML

doctype html
    link(rel='stylesheet', href='../CSS/requirements.css')
    script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js')
    body
      p = content

When starting the server I receive this error message

Error: C:\Users\mah\Desktop\Test\views\index.pug:2:1
    1| doctype html

  > 2|     link(rel='stylesheet', href='../CSS/requirements.css')

-------^
    3|     script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js')

    4|     body

    5|       p = content


unexpected token "indent"
    at makeError (C:\Users\mah\Desktop\Test\node_modules\pug-error\index.js:32:13)
    at Parser.error (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:53:15)
    at Parser.parseExpr (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:264:14)
    at Parser.parse (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:112:25)
    at parse (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:12:20)
    at Object.parse (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:126:22)
    at Function.loadString [as string] (C:\Users\mah\Desktop\Test\node_modules\pug-load\index.js:45:21)
    at compileBody (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:86:18)
    at Object.exports.compile (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:243:16)
    at handleTemplateCache (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:216:25)

Could someone help me out here?

agit

I think you forget html just after doctype html.

doctype html
html
  link(rel='stylesheet', href='../CSS/requirements.css')
  script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js')
  body
    p=content

doctype html and html should be at same intent level. Btw, change p = content to p=content to print passed value

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

syntax error near unexpected token `>' when using '&>>' redirection operator

Uncaught SyntaxError: Unexpected token < when using bootstrap js

Unexpected token '@' when using ES6 decorators

Unexpected Token @ when using babel decorator

Unexpected token error when using ionic/cordova

In Django, how can I generate csrf token when not using templates

unexpected token import when using Mocha with Babel

"Unexpected Token" when using the map function in React

Unexpected token `tag` expected in pug

Uncaught SyntaxError: Unexpected token when using leaflet with flask

Suddenly getting "syntaxerror: Unexpected Token" in PUG CLI

IndentationError: unexpected indent - Using Variable in a String

Unexpected token when using map

Unexpected token "." when using .bind() in JavaScript

Uncaught SyntaxError: Unexpected token . when using ClassNotty

Unexpected indent when using save function

unexpected token when building array of object using variable

Unexpected token error when using PHP with JavaScript

Unexpected token when using different property name in object literal

Parsing error: Unexpected token .. when using eslint

Jquery unexpected token when using a function

Unexpected token < when using reactjs app

unexpected token:where when using spring data jpa with hibernate

React "return" unexpected token when using babelify

using pycodejs to parse pug templates with mixin blocks and crete django templates

"Unexpected token ." when using optional chaning "?." syntax when running mocha

Module parse failed: Unexpected token when using webpack 5

Jest Unexpected token 'export' when using d3

Misplaced link and meta tags in Pug templates when using webpack (prismic cms)