简体   繁体   English

Gulp fontgen失败,因为“ TypeError:无法读取未定义的属性'replace'”

[英]Gulp fontgen fails because “TypeError: Cannot read property 'replace' of undefined”

I'm starting with a gulp-fontgen project, but I got an error when I run it with gulp command: 我从一个gulp-fontgen项目开始,但是用gulp命令运行它时出现错误:

TypeError: Cannot read property 'replace' of undefined

My gulpfile: 我的gulpfile:

var gulp = require('gulp');
var fontgen = require('./node_modules/gulp-fontgen');

gulp.task('fontgen', function() {
  return gulp.src("./assets/*.{ttf,otf}")
    .pipe(fontgen({
      dest: "./dest/"
    }));
});

gulp.task('default', ['fontgen']);

My package.json: 我的package.json:

{
  "name": "garagord-webfont",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-fontgen": "^0.2.4"
  }
}

Entire terminal output: 整个终端输出:

$ gulp
[11:26:24] Using gulpfile /Volumes/B/Documentos/tipografia-garagord/Gulp/gulpfile.js
[11:26:24] Starting 'fontgen'...
/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/fontfacegen/lib/configure.js:19
    _.config_file  = _.source.replace(_.extension, '') + '.json';
                             ^

TypeError: Cannot read property 'replace' of undefined
    at module.exports (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/fontfacegen/lib/configure.js:19:30)
    at module.exports (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/fontfacegen/lib/fontfacegen.js:16:18)
    at DestroyableTransform._transform (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/gulp-fontgen/lib/gulp-fontgen.js:47:31)
    at DestroyableTransform.Transform._read (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
    at doWrite (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
    at writeOrBuffer (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
    at DestroyableTransform.Writable.write (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
    at write (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Volumes/B/Documentos/tipografia-garagord/Gulp/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)

The gulp-fontgen plugin is horribly broken. gulp-fontgen插件严重损坏。 Just take a look at the source code : 只需看一下源代码即可

return _through2.default.obj(function (file, enc, callback) {
  // options.source = file.path;
  (0, _fontfacegen2.default)(options);

  undefined.push(file);
  return callback();
});

The commented out line above is what is causing your error. 上面的注释行是导致您出错的原因。 The source option is not passed along to fontfacegen . source选项没有传递给fontfacegen Even if you uncomment that line there's a freaking undefined.push(file); 即使您取消注释该行,也会出现undefined.push(file); in there which cannot possibly work (lesson: don't take drugs, kids, and always write your unit tests). 在那可能行不通的地方(课程:不要吸毒,不要孩子,要经常写单元测试)。

My suggestion: don't use gulp-fontgen . 我的建议:不要使用gulp-fontgen The plugin is really just a thin wrapper around fontfacegen . 该插件实际上只是fontfacegen的薄包装。 You can easily replace it by using fontfacegen directly in combination with map-stream : 您可以通过直接将fontfacegenmap-stream结合使用来轻松替换它:

var gulp = require('gulp');
var fontfacegen = require('fontfacegen');
var map = require('map-stream');

gulp.task('fontgen', function() {
  return gulp.src("./assets/*.{ttf,otf}")
    .pipe(map(function(file, cb) {
      fontfacegen({
        source: file.path,
        dest: './dest/'
      });
      cb(null, file);
    }));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取未定义吞咽的属性“应用” - cannot read property 'apply' of undefined gulp 类型错误:无法读取未定义的属性“节点” - TypeError: Cannot read property 'node' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ close” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined [TypeError:无法读取未定义的属性“GlobalWorkerOptions”] - [TypeError: Cannot read property 'GlobalWorkerOptions' of undefined] 无法`gulp install`,导致`Cannot read property 'apply' of undefined` - Cannot `gulp install`, results in `Cannot read property 'apply' of undefined` bower TypeError无法读取未定义的属性“链接” - bower TypeError Cannot read property 'linked' of undefined TypeError:无法读取未定义的Webpack的属性“ 0” - TypeError: Cannot read property '0' of undefined Webpack 未捕获的TypeError:无法读取未定义的属性“布尔” - Uncaught TypeError: Cannot read property 'bool' of undefined Laravel TypeError:无法读取未定义的属性“js” - Laravel TypeError: Cannot read property 'js' of undefined 类型错误:无法读取未定义的属性“webpackJsonp” - TypeError: Cannot read property 'webpackJsonp' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM