EJS 变量在 <script> 标签内工作,但 vscode 抛出错误

Sai*_*han 4 javascript ejs visual-studio-code

我在脚本标签中有一个 ejs 变量,它工作正常,但 vscode 抛出错误,说“需要表达式”这是代码

 <script type="text/javascript">
      var currentUser= <%- JSON.stringify(currentUser) %>
      console.log(currentUser);
    </script>
Run Code Online (Sandbox Code Playgroud)

我们可以看到 vscode 突出显示了错误

但它正在工作,我能够在浏览器控制台中看到 currentUser 对象 控制台截图

我无法弄清楚是什么导致了这个问题。有人可以帮我解决这个问题吗?

小智 6

在 VS-Code 中更新此设置

"html.validate.scripts": false
Run Code Online (Sandbox Code Playgroud)

源链接:https ://github.com/microsoft/vscode/issues/51118