gpt4 book ai didi

node.js - gulp-jade 报告错误,如 'Cannot read property ' xxx' of undefined'

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:41 24 4
gpt4 key购买 nike

当我使用 gulp-jade@1.1.0 编译“index.jade”时

<!DOCTYPE html>
html(lang="en")
head
meta(charset="UTF-8")
title Document
body
- var json = {'foo': 'bar'}
include template

包括“template.jade”

h1= json.foo

gulp-jade 总是报告这样的错误

[15:11:34] Starting 'jade'...
[15:11:34] Starting 'sass'...
[15:11:34] Finished 'sass' after 2.68 ms
[15:11:34] Plumber found unhandled error:
TypeError in plugin 'gulp-jade'
Message:
C:\Users\Administrator\Desktop\workspace\node\src\jade\template.jade:1
> 1| h1= json.foo

Cannot read property 'foo' of undefined
Details:
path: C:\Users\Administrator\Desktop\workspace\node\src\jade\template.jade
[15:11:34] Finished 'jade' after 19 ms

但是编译后的html文件是正确的

<!DOCTYPE html>
<html lang="en"></html>
<head>
<meta charset="UTF-8"/>
<title>Document</title>
</head>
<body>
<h1>bar</h1>
</body>

我的 gulpfile 是这样写的

gulp.task('jade', function(){
return gulp.src('src/jade/*.jade')
.pipe(plumber())
.pipe(gulpJade({
jade: jade,
pretty: true
}))
.pipe(gulp.dest('build/html'))
.pipe(connect.reload());
});

最佳答案

Gulp 尝试单独编译每个模板。

您必须仅指定入口点 (index.jade):

gulp.task('jade', function(){
return gulp.src('src/jade/index.jade')
.pipe(plumber())
.pipe(gulpJade({
jade: jade,
pretty: true
}))
.pipe(gulp.dest('build/html'))
.pipe(connect.reload());
});

或从gulp.src中排除template.jade

关于node.js - gulp-jade 报告错误,如 'Cannot read property ' xxx' of undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33164645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com