Sp-dev-docs: Error - TypeError: this.log is not a function

Created on 5 Dec 2019  Â·  6Comments  Â·  Source: SharePoint/sp-dev-docs

When adding this.log to custom subtasks I'm getting the error listed in the title.
v1.9.1 of SPFx.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

docs-comment spfx-general answered question

All 6 comments

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

Could you provide more details?

I did sample test in my local environment while can't reproduce.

`'use strict';

const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
build.addSuppression(Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.);

let helloWorldSubtask = build.subTask('log-hello-world-subtask', function(gulp, buildOptions, done) {
this.log('Hello, World!');
// use functions from gulp task here
done();
});

build.rig.addBuildTasks(helloWorldSubtask);
build.initialize(gulp);
`

image

Or

const gulp = require('gulp'); const build = require('@microsoft/sp-build-web'); build.addSuppression(Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);

let helloWorldSubtask = build.subTask('log-hello-world-subtask', function(gulp, buildOptions, done) {
this.log('Hello, World!');
// use functions from gulp task here
done();
});

//build.rig.addBuildTasks(helloWorldSubtask);
// Register the task with gulp command line
let helloWorldTask = build.task('hello-world', helloWorldSubtask);
build.initialize(gulp);`

image

Lee
Microsoft SharePoint Community Support

Hi @OS-Lee,

Sorry, my bad in initial description. The project is on version 1.8.2.
The code:

'use strict';

const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');

let updateVersionTask = build.subTask('update-version', (gulp, buildOptions, done) => {
    this.log('TEST');
    done();
});

build.rig.addPreBuildTask(updateVersionTask);

build.initialize(gulp);

Define the function as

let updateVersionTask = build.subTask('update-version', function(gulp, buildOptions, done){    
    this.log('TEST');
    done();
});

will fix the error based on my testing.

Lee
Microsoft SharePoint Community Support

Yep, arrow function replaces the context! Thanks!

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonthenerd picture jonthenerd  Â·  3Comments

jonthenerd picture jonthenerd  Â·  3Comments

byrongits picture byrongits  Â·  3Comments

waldekmastykarz picture waldekmastykarz  Â·  3Comments

StfBauer picture StfBauer  Â·  3Comments