jade the “filename” option is required to use “ext

2019-06-01 09:54发布

I have following folder structure (simplified):

project - app.js - views - index.jade - layout.jade - public ...

I want to generate an index.html file from index.jade and use the following command in my Terminal (Mac OS X):

jade < index.jade > index.html

However I receive an error saying:

/usr/local/lib/node_modules/jade/lib/runtime.js:231 throw err; ^ Error: Jade:1

1| extends ./layout

2|

3| block mainContent

4|   center

the "filename" option is required to use "extends" with "relative" paths at Parser.resolvePath (/usr/local/lib/node_modules/jade/lib/parser.js:464:13) at Parser.parseExtends (/usr/local/lib/node_modules/jade/lib/parser.js:483:21) at Parser.parseExpr (/usr/local/lib/node_modules/jade/lib/parser.js:221:21) at Parser.parse (/usr/local/lib/node_modules/jade/lib/parser.js:122:25) at parse (/usr/local/lib/node_modules/jade/lib/index.js:102:21) at Object.exports.compile (/usr/local/lib/node_modules/jade/lib/index.js:172:16) at ReadStream. (/usr/local/lib/node_modules/jade/bin/jade.js:144:21) at ReadStream.emit (events.js:117:20) at _stream_readable.js:943:16 at process._tickCallback (node.js:419:13)

I tried editing the line which causes the error in index.jade to:

extends layout

and

extends layout.jade

and

extends ./layout.jade

Any idea how I could fix this?

3条回答
别忘想泡老子
2楼-- · 2019-06-01 10:08

if use "extend" or "include", the filename option must be used.

--filename "/absulute/path/to/your-file.jade"
查看更多
虎瘦雄心在
3楼-- · 2019-06-01 10:13

You have to set -p option:

jade -p src/index.jade < src/index.jade > build/index.html

Be careful! Jade drops last component of -p argument to concatenate with relative path.

查看更多
Viruses.
4楼-- · 2019-06-01 10:15

You get the error because you are trying with

jade < index.jade > index.html

so jade have troubles finding the path (not sure why I think this is an issue) but if you try

jade < index.jade >

everything will be smooth.

or maybe try some automation with http://gulpjs.com/

查看更多
登录 后发表回答