No gulpfile found error in SPFx – when we work on the SPFx framework project, after running the “yo @microsoft/sharepoint” command, if we try to run the “Gulp serve” or “Gulp build” command we will get the error “No gulpfile found“.
What is the root cause of the “No gulpfile found” error (No gulpfile found error in SPFx)?
The root cause of this error is – it is trying to find the gulpfile.js in the project directory but it does not exist. To fix this error we need to add gulpfile.js to the project directory root by running the command
touch gulpfile.js
Note:
Make sure the ‘touch’ command is installed in the project directory using the npm install touch-cli -g otherwise we will get the below error:
'touch' is not recognized as an internal or external command, operable program or batch file.
Then, run the touch gulpfile.js command.
On a successful run, we should see the command prompt return “Touching gulpfile.js” message.
After adding gulpfile.js in the project directory if we run gulp command, we will get a new error, Task ‘default’ is not in your gulpfile – Please check the documentation for proper gulpfile formatting.
The above error means that the gulpfile.js just created by the command does not have a default task in the gulpfile.js. Each gulpfile needs a default task to run when gulp is executed without any arguments. So we should add a default task in the newly created gulpfile by adding the below texts – just open the gulpfile.js in the notepad editor and add the below texts:
var gulp = require('gulp'); gulp.task('default', function() { //Here is the code for the default task });
Now when we run the gulp command we get the below output.
Starting ‘default’…
Default Gulp!
Finished ‘default’ after 509 μs
Now we can say that our gulp process is up and running in our SPFx project directory.
Summary: No gulpfile found error in SPFx
Thus in this troubleshooting technique, how to fix No gulpfile found in SPFx framework project.
Other relevant gulp commands:
npm install gulp-cli -g npm install gulp -D touch gulpfile.js gulp --help
See Also: SPFx Tutorial step by step
You may also like the below SharePoint SPFx articles:
- SharePoint Online: CRUD operations using SPFx no javascript framework
- Develop your first hello world web part in sharepoint framework (SPFx)
- Understanding solution structure in SharePoint framework (SPFx)
- Create custom property in SharePoint Framework – SPFx web part pane
- Get list items from SharePoint using SPFx framework(No Javascript Framework)
- Custom search result page in SharePoint Online – SPFx PnP Modern Search solution
- GitHub Reference