全新的Express项目出现错误:doctype 5已被弃用,现在必须使用doctype html。

26
在Windows命令提示符上运行以下命令创建了一个全新的express.js项目。
npm install express -g 
express newproject
cd newproject
npm install
node app

我随后打开浏览器窗口访问 http://localhost:3000/,但是遇到了以下错误。

    500 Error: c:\projects\newproject\views\index.jade:5<br/> 3| block content <br/> 4| h1= title <br/> > 5| p Welcome to #{title}<br/><br/>`doctype 5` is deprecated, you must now use `doctype html`
3| block content 
4| h1= title 
> 5| p Welcome to #{title}

`doctype 5` is deprecated, you must now use `doctype html`
at Object.Compiler.setDoctype (c:\projects\newproject\node_modules\jade\lib\compiler.js:68:13)
at Object.Compiler.visitDoctype (c:\projects\newproject\node_modules\jade\lib\compiler.js:312:12)
at Object.Compiler.visitNode (c:\projects\newproject\node_modules\jade\lib\compiler.js:210:37)
at Object.Compiler.visit (c:\projects\newproject\node_modules\jade\lib\compiler.js:197:10)
at Object.Compiler.visitBlock (c:\projects\newproject\node_modules\jade\lib\compiler.js:278:12)
at Object.Compiler.visitNode (c:\projects\newproject\node_modules\jade\lib\compiler.js:210:37)
at Object.Compiler.visit (c:\projects\newproject\node_modules\jade\lib\compiler.js:197:10)
at Object.Compiler.compile (c:\projects\newproject\node_modules\jade\lib\compiler.js:52:10)
at parse (c:\projects\newproject\node_modules\jade\lib\jade.js:96:23)
at Object.exports.compile (c:\projects\newproject\node_modules\jade\lib\jade.js:152:9)
3个回答

50

为了修复你当前的项目和使用当前版本的Express构建的任何项目,请前往你的layout.jade文件并将第一行更改为:doctype html(第二行应该是:html)

这个问题已经被发现并解决,所以在未来版本的Express中不会再成为问题。 https://github.com/visionmedia/express/pull/1875


1
感谢更新。更改layout.jade已解决问题,直到修复在下一个版本中包含为止。 - Bryan Focht

15
使用:

1
在您全新的项目中,将views/layout.jade第一行的"doctype 5"更改为"doctype html"。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接