gulp : "TypeError: print is not a function"
Asked Answered
L

2

7

I am trying to build Semantic-UI with gulp in a directory, but I get having these errors :

root@ks4000003:/var/www/mg.guylabbe.ca/web/inc/semantic# gulp build
[10:36:53] Using gulpfile /var/www/clients/client1/web179/web/inc/semantic/gulpfile.js
[10:36:53] Starting 'build'...
Building Semantic
[10:36:53] Starting 'build-javascript'...
Building Javascript
[10:36:54] 'build-javascript' errored after 19 ms
[10:36:54] TypeError: print is not a function
    at Gulp.module.exports (/var/www/clients/client1/web179/web/inc/semantic/tasks/build/javascript.js:64:11)
    at module.exports (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:134:8)
    at runNextSet (/var/www/clients/client1/web179/web/inc/node_modules/run-sequence/index.js:124:15)
    at runSequence (/var/www/clients/client1/web179/web/inc/node_modules/run-sequence/index.js:136:2)
    at Gulp.module.exports (/var/www/clients/client1/web179/web/inc/semantic/tasks/build.js:49:3)
    at module.exports (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:273:3)
[10:36:54] 'build' errored after 21 ms
[10:36:54] TypeError in plugin "run-sequence(build-javascript)"
Message:
    print is not a function
Stack:
TypeError: print is not a function
    at Gulp.module.exports (/var/www/clients/client1/web179/web/inc/semantic/tasks/build/javascript.js:64:11)
    at module.exports (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:134:8)
    at runNextSet (/var/www/clients/client1/web179/web/inc/node_modules/run-sequence/index.js:124:15)
    at runSequence (/var/www/clients/client1/web179/web/inc/node_modules/run-sequence/index.js:136:2)
    at Gulp.module.exports (/var/www/clients/client1/web179/web/inc/semantic/tasks/build.js:49:3)
    at module.exports (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/var/www/clients/client1/web179/web/inc/node_modules/orchestrator/index.js:273:3)

If I check javascript.js file, gulp-print is correctly loaded :

var print = require('gulp-print');

and used (8th line below) :

  // copy source javascript
  gulp.src(source.definitions + '/**/' + globs.components + '.js')
    .pipe(plumber())
    .pipe(flatten())
    .pipe(replace(comments.license.in, comments.license.out))
    .pipe(gulp.dest(output.uncompressed))
    .pipe(gulpif(config.hasPermission, chmod(config.permission)))
    .pipe(print(log.created))
    .pipe(uglify(settings.uglify))
    .pipe(rename(settings.rename.minJS))
    .pipe(gulp.dest(output.compressed))
    .pipe(gulpif(config.hasPermission, chmod(config.permission)))
    .pipe(print(log.created))
    .on('end', function() {
      gulp.start('package compressed js');
      gulp.start('package uncompressed js');
      callback();
    })
  ;

Gulp version :

[10:42:25] CLI version 3.9.1
[10:42:25] Local version 3.9.1

Does anybody has thoughts on this problem? Thank you!

Lorielorien answered 11/3, 2018 at 14:50 Comment(4)
It looks like gulp-print can take a function that returns a string. Is log.created a function? It cannot be a string. But easy to change if that is what you want. Perhaps this is the source of your errors.Salvo
Thank you @Mark; even if your comment was not a direct answer to my problem, this did encouraged me to look up variables (printing them with console.log()). A look into gulp-print helped understanding that I had to edit code a little bit. I will write the solution as an answer. This is still weird though, because this is not a custom script.Lorielorien
Well, that plugin is very non-standard! See github.com/alexgorbatchev/gulp-print/issues/20 for users trying to fix this problem. I didn't catch your fix because I've never had to do that for a gulp plugin.Salvo
I didn't come across this one while searching... thank you very much! They are using a similar solution as the one I proposed (probably a bit better hehe)Lorielorien
L
9

gulpPrint function is default export, therefore, I need to add a bit of code while importing gulp dependencies. Replace :

var print        = require('gulp-print');

by :

var print        = require('gulp-print').default;
// usage
print();

so the gulpPrint(); function is renamed print();

or can also be used in the following way:

var print = require('gulp-print');
// usage
print.default()

In case of doubt, dump variable contents with console.log(print), for instance. It will help a lot to understand the logic behind it if you are a beginner like me.

Lorielorien answered 12/3, 2018 at 17:52 Comment(1)
On Semantic UI 2.4.0, the above change needs to be made in tasks/build/css.js and tasks/build/javascript.jsMasaccio
S
3

Changes described in the first answer are already in semantic-ui guilpfile.js. However, I have got the same error while running gulp build.

The reason for that was the old version of gulp-print. After update to the newest version gulp was building fine:

npm install [email protected] --save-dev
Sherard answered 31/10, 2018 at 22:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.