Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

331
Views
escribir ejs en un script me da el error 'Expresión esperada'

Tengo una etiqueta de script en mi archivo show.ejs y tengo la siguiente línea:

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

Recibo el error de 'Error esperado' en las etiquetas ejs de apertura y cierre. Me preguntaba por qué ocurre este error y si hay algo que estoy haciendo que no esté permitido.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Solo tengo el mismo problema con el código VS si usa VS, necesita agregar al final de settings.json en la configuración de html esta línea

 "html.validate.scripts": false,

encuentra html en la parte inferior derecha encuentra html en la parte inferior derecha

luego busque configurar lenguaje HTMLluego busque configurar lenguaje HTML y agregue una línea al final del archivo json y agregue una línea al final del archivo json

over 4 years ago · Santiago Trujillo Report

0

Hay 2 formas opcionales.

1)

Cambie los delimitadores globales de EJS.

 const ejs = require("ejs"); ejs.delimiter = '/'; ejs.openDelimiter = '['; ejs.closeDelimiter = ']';

Actualice su guión.

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

2)

Agregue esta propiedad a settings.json en VSCode.

 "html.validate.scripts": false

Cambie los delimitadores globales de EJS.

 const ejs = require("ejs"); ejs.delimiter = '?'; ejs.openDelimiter = '['; ejs.closeDelimiter = ']';

Actualice su guión.

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

Nota: El formato automático funcionará correctamente de 2 maneras.

Nota: prefiero el primero porque puedo usar tanto el formato automático como la validación de scripts y no necesito ninguna extensión EJS.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!