sindresorhus / gulp-nunjucks

Precompile Nunjucks templates
MIT License
152 stars 20 forks source link

First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. #36

Open Kaito23 opened 5 years ago

Kaito23 commented 5 years ago

Hey, I have a problem while compiling my project.

Infos: package.json

 {
  "name": "node",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "replacer": "node replacer.js",
    "gulp": "gulp"
  },
  "author": "me",
  "license": "MIT",
  "devDependencies": {
    "browser-sync": "^2.18.13",
    "csslint": "^1.0.5",
    "gulp": "^3.9.1",
    "gulp-clean-css": "^3.10.0",
    "gulp-cli": "^1.3.0",
    "gulp-csslint": "^1.0.1",
    "gulp-less": "^3.3.2",
    "gulp-nunjucks": "^4.0.0",
    "gulp-nunjucks-render": "^2.2.2",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^4.0.2",
    "gulp-util": "^3.0.8",
    "node-sass": "^4.11.0",
    "nunjucks": "^3.1.7",
    "stream-combiner2": "^1.1.1"
  }
}

my gulpfile:

// Include gulp
var gulp = require('gulp');

// Include Our Plugins
var sass = require('gulp-sass');
var browserSync = require('browser-sync');
var reload      = browserSync.reload;
var util = require('gulp-util');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var nunjucks = require('gulp-nunjucks');
var cleanCSS = require('gulp-clean-css');
var csslint = require('gulp-csslint');

var cssLintConfig = {<lint config>}
// lint css
gulp.task('csslint', function() {<some code here>});

// Compile Our css
gulp.task('sass', function() {<some code here>});
// browser-sync
gulp.task('browser-sync', function () {<some code here>});

gulp.task('nunjucks', () =>
    gulp.src('pages/base.html')
        .pipe(nunjucks.compile().on('error', function(error){
            console.log(error);
        }))
        .pipe(gulp.dest('public'))
          .pipe(reload({stream: true}))
);

// Watch Files For Changes
gulp.task('watch', function() {<some code here>});

gulp.task('minify-css', () => {<some code here>});

// Default Task
gulp.task('default', ['nunjucks', 'sass', 'watch', 'browser-sync']);

the error stack:

[07:30:46] Starting 'nunjucks'...
[07:30:47] { TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
    at Function.Buffer.from (buffer.js:183:11)
    at DestroyableTransform._transform (<root>/node_modules/gulp-nunjucks/index.js:29:27)
    at DestroyableTransform.Transform._read (<root>/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (<root>/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (<root>/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (<root>/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (<root>/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at write (<root>/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (<root>/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (<root>/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:664:5)
  message: 'First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.',
  name: 'TypeError',
  stack: 'TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.\n    at Function.Buffer.from (buffer.js:183:11)\n    at DestroyableTransform._transform (<root>/node_modules/gulp-nunjucks/index.js:29:27)\n    at DestroyableTransform.Transform._read (<root>/node_modules/readable-stream/lib/_stream_transform.js:184:10)\n    at DestroyableTransform.Transform._write (<root>/node_modules/readable-stream/lib/_stream_transform.js:172:83)\n    at doWrite (<root>/node_modules/readable-stream/lib/_stream_writable.js:428:64)\n    at writeOrBuffer (<root>/node_modules/readable-stream/lib/_stream_writable.js:417:5)\n    at DestroyableTransform.Writable.write (<root>/node_modules/readable-stream/lib/_stream_writable.js:334:11)\n    at write (<root>/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:623:24)\n    at flow (<root>/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:632:7)\n    at DestroyableTransform.pipeOnReadable (<root>/node_modules/vinyl-fs/node_modules/readable-stream/lib/_stream_readable.js:664:5)',
  __safety: undefined,
  _stack: undefined,
  plugin: 'gulp-nunjucks',
  showProperties: true,
  showStack: false,
  fileName: '<root>/pages/base.html' }

it seems to happen when files get too big. Are there any known problems? I have created a nunjucks vanilla build and it runs fine:

// Nunjucks
fs = require('fs');
nunjucks = require('nunjucks');

nunjucks.render('./pages/base.html',function(err, res) {
    //console.log(res);
    fs.writeFile('test.html', res, function(err) {
        if (err) throw err;
    });  
    console.log("---");
    console.log("Error " + err); // returns null
});

any ideas how to solve the error above? Or is there maybe a misconfig?

aerth commented 4 years ago

for me, it was importing a file that included a bad include.

example:

{% include "not-found/404.html" %}

the error given by gulp-nunjucks could include line number and actual filename and that would help a lot.