Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

598
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda