In this SPFx tutorial, we will discuss how to fix an error, no gulpfile found spfx. The error comes when you run the gulp serve command to run an SPFx client side web part.
If you follow the MSDN article to set up your SPFx development environment, then you might not get this issue. But if you still getting the error, no gulpfile found while running the gulp trust-dev-cert or gulp serve then follow the below solution.
If you are new to SPFx development, I have written a complete article on how to set up a development environment for SPFx and also create your first SPFx client-side web part.
When you start developing an SPFx web part, after running the yo @microsoft/sharepoint command, you might get the no gulpfile found error while running any of the below commands:
- gulp trust-dev-cert
- gulp build
- gulp serve
The error you will get, when the gulpfile.js will not be found in the project directory.
To fix the issue, in the same directory, you can run the following command:
npm install touch-cli -g (Run if you never installed touch-cli in your system)
touch gulpfile.js (Then run this command)
Once you run the command, we need to add the default task in the gulpfile.js else you will get the below error:
Task ‘default’ is not in your gulpfile – Please check the documentation for proper gulpfile formatting.
To add a default task in the gulpfile.js file, open the file in visual studio code (even you can open in a notepad file) and then add the below code:
var gulp = require('gulp');
gulp.task('default', function() {
//Here is the code for the default task
});
Then you run the gulp serve command and you will not get the no gulpfile found error in your SPFx project.
no gulpfile found error
Apart from this you can also try the following solutions:
Once you get the error, you can run the below command:
npm install --save-dev gulp
Apart from that also, if you want, you can install the particular gulp version in your system like:
npm install - gulp@3.9.0
And you can run the below command to check the gulp version.
gulp -v
You might like the following SPFx tutorials:
- SPFx – Bind dropdown list from SharePoint list using PnP
- What is Microsoft Fluent UI (with React)
- Delete node_modules from SPFx solution (rimraf)
- Create and deploy SharePoint Framework (SPFx) listview command set extension
- Create and Deploy SharePoint Framework (SPFx) extension field customizer
- SharePoint Framework (SPFx) Extensions Application Customizer Example
- The entry point for component has a dependency on “@microsoft/sp-http” that is not declared in the manifest react spfx
- Can’t load the application on this page. Use the browser Back button to retry while adding SPFx web part into Microsoft Teams
- How to Create Site Columns, Content Type and Custom List using SharePoint Framework
- cannot find module jquery spfx
This is how we can fix no gulp file found error in spfx.
- no gulpfile found spfx
- no gulpfile found gulp serve
- no gulpfile found error
- no gulpfile found visual studio code
- no gulpfile found gulp trust-dev-cert
I am Bijay a Microsoft MVP (8 times – My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com

In this post we are going to discuss about how to solve no gulpfile found error. In our previous post we have explained about Configuring System for using TypeScript where we have explained how to install gulp (A JavaScript Task Runner).
Now after installing gulp using npm install gulp -g when you run gulp in the command line you might get an error as No gulpfile found error.

This error means that gulp doesn’t find gulpfile.js to follow the instructions. To solve this error we simply need to add gulpfile.js to our directory root by running the command
touch gulpfile.js
Now after adding gulpfile.js if we run gulp command again we will get a new error, Task ‘default’ is not in your gulpfile, as shown below.

The above error means that we do not have a default task in our gulpfile.js. Every gulpfile needs a default task to run when gulp is executed without any arguments. So we are going to add a default task in our gulpfile.
var gulp = require(‘gulp’);
gulp.task(‘default’, function () { console.log(‘Hello Gulp!’) });
Now when we run the gulp command we get the following output. Thus our gulp process is up and running.

Please Like and Share the CodingDefined.com Blog, if you find it interesting and helpful.
Я пытаюсь помочь удаленному коллеге установить gulp в Windows, чтобы он мог скомпилировать один из наших проектов JavaScript локально. Сотрудник до меня пытался помочь этому удаленному коллеге более года, прежде чем я пришел сюда, но без особой пользы, так что, возможно, с того времени в корне проблемы осталась некоторая грязь, но я сделал то, что думал разумно начать с нуля, и у меня по-прежнему есть та же проблема.
Я отправил ему папку проекта, точно клонированную в том виде, в котором она есть у меня, за исключением папки node_modules. Я попросил его сначала удалить и переустановить Node, используя первые три трех шаги этого ответа с последующей повторной загрузкой MSI с NodeJS.org для повторной установки. Затем в рабочем каталоге я заставил его запустить
PS C:UsersCoworkerPathToProject>npm ci
Установить gulp. gulp и его различные расширения — единственные модули в папке package.json, а package-lock.json — это просто результат недавней успешной установки этих пакетов. Содержание package.json:
{
"devDependencies": {
"gulp": "^4.0.0",
"gulp-coffee": "latest",
"gulp-concat": "latest",
"gulp-concat-sourcemap": "latest",
"gulp-connect": "latest",
"gulp-minifier": "latest",
"gulp-minify-css": "latest",
"gulp-remove-logging": "latest",
"gulp-resolve-dependencies": "latest",
"gulp-sass": "latest",
"gulp-uglify": "latest",
"gulp-util": "latest",
"gulp-watch": "latest",
"gulp-wrap": "latest"
},
"dependencies": {
"natives": "^1.1.6"
}
}
Я также попросил его удалить и переустановить gulp-cli во всем мире.
npm uninstall --global gulp gulp-cli
npm install --global gulp-cli
При выполнении gulp --version отображается правильный ожидаемый результат:
PS C:UsersCoworkerPathToProject>gulp --version
CLI version: 2.2.0
Local version: 4.0.0
Это соответствует выводу на моем компьютере с Windows, где все работает нормально.
Когда мы наконец заставим его запустить gulp в каталоге проекта, он просто даст:
PS C:UsersCoworkerPathToProject> gulp
No gulpfile found
Единственный полезный вопрос, который уже есть в Stack Overflow для этого, — здесь, и каждый ответ имеет некоторую форму из «добавить gulpfile». Но в рабочем каталоге есть файл gulpfile.js. У него правильное имя и расширение файла. Он отформатирован правильно. Это точная копия файла в моем собственном локальном каталоге, который, когда я запускаю ту же команду, он безупречно проглатывает. Что может быть причиной того, что gulp не распознает наличие gulpfile? Может быть, gulp неправильно настроен и пытается работать с другим рабочим каталогом, несмотря на каталог, в котором он вызывается? Как я могу решить эту проблему?
First, let’s make sure we have node and npm installed:
$ node -v v0.10.25 $ npm -v 1.3.24
Now let’s try to run gulp. If everything goes to plan, we should see our first error:
$ gulp
command not found: gulp
Perfect! Let’s ask NPM for a fresh copy of gulp:
$ npm install gulp -g ... installing gulp ...
This installs gulp command-line utility and makes available globally. Now, let’s try running gulp again:
$ gulp [gulp] No gulpfile found
Nice, our first error!
gulp is telling us that it doesn’t have a gulpfile with instructions for it to follow. We solve this by simply adding gulpfile.js to our directory root:
We haven’t added any instructions but sipmly having having the file should give us a new error:
$ gulp [gulp] Using gulpfile /Users/chan/code/talks/gulpfile.js [gulp] Task 'default' was not defined in your gulpfile but you tried to run it. [gulp] Please check the documentation for proper gulpfile formatting.
Boom! Now we’re talking. gulp is running and it sees our gulpfile. We’re on a roll!
It tells us that we don’t have a default task. Every gulpfile needs a default task to run, when gulp is executed without arguments.
We find the syntax for creating a gulp task in their docs. Looks like it’s gulp.task('taskName');. Let’s try it:
$ echo "gulp.task('default');" >> gulpfile.js $gulp ... ReferenceError: gulp is not defined ...
Yuck! Now we have a really ugly error…
But don’t lose heart. This error looks scarier than it is.
node is telling us that there is no reference to ‘gulp’ in our file. We simply need to add a reference to gulp in our gulpfile:
[ add the following line to the very top of your gulpfile ]
// gulpfile.js var gulp = require('gulp');
Now that we’ve told node what gulp means, in our script, lets try running gulp again:
$ gulp [gulp] Using gulpfile /Users/chan/code/talks/gulpfile.js [gulp] Starting 'default'... [gulp] Finished 'default' after 71 μs
Hurray! We now have a working gulpfile that does nothing! Pat yourself on the back firmly.
Adding a process
Now, gulp just sits on top of node. So, we can do anything we could do node:
// gulpfile.js // update our default task with a function gulp.task('default', function () { console.log('Hello Gulp!') });
Run this and we’ll see Hello Gulp! amidst the gulp output:
$ gulp [gulp] Using gulpfile /Users/chan/code/talks/gulpfile.js [gulp] Starting 'default'... Hello Full Stack [gulp] Finished 'default' after 137 μs
This is particularly unuseful. So, let’s turn this into something that can compile CoffeeScript into JavaScript.
Let’s start with a new task for this: gulp scripts.
We’re going to mimic what we did with our default task. gulp gives great errors. It’s easy to start with the process you want and respond to the errers until it works.
Let’s try gulp scripts
$ gulp scripts [gulp] Using gulpfile /Users/chan/code/talks/gulpfile.js [gulp] Task 'scripts' was not defined in your gulpfile but you tried to run it. [gulp] Please check the documentation for proper gulpfile formatting.
As I’m sure you expected, this fails. We haven’t written a scripts task. Let’s write it now.
[ add this to your gulpfile ]
// gulpfile.js gulp.task('scripts', function () { gulp.src('src/*.coffee').pipe(gulp.dest('./')); });
There’s a lot of code we haven’t covered here. So take a second to look it over. It may seem jarring at first but give it a second to sink it…
Now we can talk about what it’s doing.
First, we’ve registered a new task named scripts. Much like our default task, it responds by running a function.
That function start by calling gulp.src() to collect the files in the path we specify. Here, we’re using * to say “grab any and all files in the src directory.
We then use pipe() to funnel those files through another process, gulp.dest().
gulp.dest() places the files specified with a path. In example, we’re using ./ to tell gulp that we want our finished files dumped into the root directory.
Notice how easily that reads? If you’ve been using JavaScript for a while, this should look painfully obvious.
Any ideas what will happen when we run this?
[ this section requires some previous setup. Add file src/fun.coffee for the examples to work ]
Gulp found our src/fun.coffee file and processed it by creating a new fun.coffee file in the directory root.
Great! But this isn’t exactly what we want. All we’ve done is duplicate our file in the directory root.
We need to process the CoffeScript file before placing it in the destination path.
We can accomplish this by chaining another pipe() right between gulp.src() and .pipe(gulp.dest(...)). This pipe will handle the actual processing of the file.
[ update the task to look like this ]
// gulpfile.js gulp.task('scripts', function () { gulp.src('src/*.coffee') .pipe(coffee()) .pipe(gulp.dest('./')); });
Now, when we run this, you shold have a pretty good idea what’s going to happen:
$ gulp scripts [gulp] Using gulpfile /Users/chan/code/talks/gulpfile.js [gulp] Starting 'scripts'... [gulp] 'scripts' errored after 5.17 ms coffee is not defined
That’s right. Another error!
You’ll notice that gulp is getting smarter and our errors are less scary. gulp tells us that we have another reference error. We need a coffee processor. Let’s add the reference to our gulpfile:
// gulpfile var coffee = require('gulp-coffee');
Now it should work, right?!
$ gulp scripts
Error: Cannot find module 'gulp-coffee'
AHHH! Our error is getting uglier! We have our reference but node can’t find gulp-coffee.
To add it. We turn back to our trusty package manager, NPM.
$ npm install gulp-coffee ... installing gulp-coffee ...
And now, running gulp scripts, we should get a fun.js file placed in our root directory:
$ gulp scripts $ ls fun.js gulpfile.js src
“And there was much reqoicing.”
If there is time…
It’s worth pointing out that this isn’t any better than using the coffee cli. If we have to run the gulp command each time we change our file, howe does gulp help us?
We need a way to watch the file system. And gulp.watch() helps us with exactly that.
Like gulp.task(), gulp.watch() can take a path as it’s first argument and a function as its second. But when we watch a directory, we may want to run a number of tasks!
gulp accounts for this by allowing you to send an array of task names as the second argument. Let’s create a new task watch to play with this:
// gulpfile.js gulp.task('watch', function () { gulp.watch('src/*.coffee', ['scripts']); });
Now, running gulp watch will continuously watch our file system for changes:
$ gulp watch
[ make changes to src/fun.coffee ]
Play around with src/fun.coffee and see our watch task respond in the terminal.
// fun.coffee console.log 'Hello Gulp!'
You can see that gulp is keeping an open process to re-run our task each time fun.coffee is changed. AWESOME!
Changing the default task
Sadly, we only have one task. It’d be nice to have that be our default wouldn’t it? Running gulp without arguments would save us a lot of finger fatigue.
Let’s update our default task to run scripts and watch when gulp is run without arguments.
// gulpfile.js gulp.task('default', ['scripts', 'watch']);
🙂
outro
As you can see, Gulp.js is insanely flexible, has very little configuration, and writes like application code.
I think you’ll really like using it in your projects.