Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

599
Vistas
writing ejs in a script is giving me the error 'Expression expected'

I have a script tag in my show.ejs file, and I have the following line:

<script>
    const post = <%- JSON.stringify(post) %>
</script>

I'm getting the error of 'Error Expected' on both the opening and closing ejs tags. I was wondering why this error occurs and if there was anything I'm doing that isn't allowed.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I just have same issue with VS code if you using VS you need to add to end of settings.json in cofiguration of html this line

"html.validate.scripts": false,

find html in bottom right find html in bottom right

then find configure HTML language then find configure HTML language and add line to end of json file and add line to end of json file

over 4 years ago · Santiago Trujillo Denunciar

0

There are 2 optional ways.

1)

Change the global delimiters of EJS.

const ejs = require("ejs");

ejs.delimiter = '/';
ejs.openDelimiter = '[';
ejs.closeDelimiter = ']';

Update your script.

<script>
const post= [/- JSON.stringify(post) /];
</script>

2)

Add this property to settings.json in VSCode.

"html.validate.scripts": false

Change the global delimiters of EJS.

const ejs = require("ejs");

ejs.delimiter = '?';
ejs.openDelimiter = '[';
ejs.closeDelimiter = ']';

Update your script.

<script>
const post= [?- JSON.stringify(post) ?];
</script>

Note: Auto format will work correctly in 2 ways.

Note: I prefer the first one because I can use both auto format and scripts validation and I don't need any EJS extension.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda