[求助]在 Jade 的 extends 那里出错了, 正确的用法应该是什么?
发布于 12 年前 作者 jiyinyiyong 6002 次浏览 最后一次编辑是 8 年前

Jade 的 extends 弄了半天不明白, 我出错的时候的目录结构是这样的:

➤➤ tree
.
├── app.coffee
├── html
├── lib
│   ├── content.coffee
│   ├── index.coffee
│   └── source.coffee
├── package.json
├── self
│   ├── coffee
│   │   └── h.coffee
│   ├── css
│   │   └── global.css
│   ├── jade
│   │   ├── layout.jade
│   │   └── page.jade

➤➤ cat self/jade/layout.jade 
!!!5
html
  head
    title #{title}
    meta(charset='utf-8')
    link(rel='stylesheet',href='/self/css/global.css')
    script(src='http://192.168.1.117:8072/doodle.js')
  body
    #box
      #side
        #banner
          for name in paths
            span.seperate /
            a.name(href="#{name.url}")= name.text
        #index
            for item in files
              .file
                a.filename(href='#{item.url}')= item.text
      block content
        #body this is a directory

➤➤ cat self/jade/page.jade 
extends layout.jade

block content
  #body= html

报错是这样的:

➤➤ coffee app.coffee 
Error: ./self/jade/layout.jade:1
  > 1| !!!5
    2| html
    3|   head
    4|     title #{title}

ENOENT, no such file or directory 'self/jade/layout.jade.jade'
    at Object.fs.openSync (fs.js:338:18)
    at Object.fs.readFileSync (fs.js:182:15)
    at Object.Parser.parseExtends (/opt/app/page-site/node_modules/jade/lib/parser.js:413:18)
    at Object.Parser.parseExpr (/opt/app/page-site/node_modules/jade/lib/parser.js:206:21)
    at Object.Parser.parse (/opt/app/page-site/node_modules/jade/lib/parser.js:130:25)
    at parse (/opt/app/page-site/node_modules/jade/lib/jade.js:100:62)
    at Object.exports.compile (/opt/app/page-site/node_modules/jade/lib/jade.js:163:9)
    at Object.<anonymous> (/opt/app/page-site/lib/content.coffee:32:20)
    at Object.<anonymous> (/opt/app/page-site/lib/content.coffee:95:4)
    at Module._compile (module.js:449:26)

代码在 lib/ 下面的文件夹里面:

page.path = '../self/jade/page.jade'
page.path = path.join __dirname, page.path
page.tmpl = fs.readFileSync page.path, 'utf8'
page.html = jade.compile page.tmpl,
  pretty: yes, filename: './self/jade/layout.jade'

我试过去掉后缀, 但那又提示文件找不到… Error: ENOENT, no such file or directory './self/jade/layout'

7 回复

网络课挂的, 数据结构数据库混过去的, 操作系统编译原理都没上过… 我… 总之比如遇到计算机系同学就死囧了. 以后标题不会再有这两个字了…

上面结尾写了的, 我去掉了的后缀会提示找不到文件

@saighost 不知道, 应该和计算机关系不大的吧

➤➤ coffee app.coffee 
Error: ENOENT, no such file or directory './self/jade/layout'
    at Object.fs.openSync (fs.js:338:18)
    at Object.fs.readFileSync (fs.js:182:15)
    at Object.rethrow (/opt/app/page-site/node_modules/jade/lib/runtime.js:155:27)
    at parse (/opt/app/page-site/node_modules/jade/lib/jade.js:116:13)
    at Object.exports.compile (/opt/app/page-site/node_modules/jade/lib/jade.js:163:9)
    at Object.<anonymous> (/opt/app/page-site/lib/content.coffee:32:20)
    at Object.<anonymous> (/opt/app/page-site/lib/content.coffee:95:4)
    at Module._compile (module.js:449:26)
    at Object.require.extensions..coffee (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:21:21)
    at Module.load (module.js:356:32)

@saighost 模拟路径还是, 我直接传代码吧 调试的命令在 w.sh 文件, 虽然很多不必要的命令 https://gitcafe.com/jiyinyiyong/page-site

@saighost 难道说…

➤➤ jade --version
0.27.2
➤➤ node -v
v0.8.9

我还是回去先用纯 HTML 好了 ToT 趁我名字还在 Jade 的 repo 首页升级一下版本看看. 0.27.4

@jiyinyiyong 同一个报错. 放弃了.

@saighost 终于问题可能在 Linux 了… 算了先搁着. 谢测试啦

回到顶部