In this SPFx tutorial, I will explain how to fix the error, cannot find module ‘@microsoft/sp-build-web’ that comes while working with SharePoint Framework.
cannot find module ‘@microsoft/sp-build-web’
I got this error while running the below command while developing a SharePoint client side web part using SPFx.
gulp trust-dev-cert
It gave the error message as: cannot find module ‘@microsoft/sp-build-web’. See the screenshot below:
Let us see how to fix the above error:
To solve this SharePoint Framework error, I ran the command “npm install @microsoft/sp-build-web@1.6.0” in the nodejs command prompt. The command was successfully executed, and the problem was solved.
If the above solutions did not work, try the below solutions which may work for you.
gulp trust-dev-cert error: cannot find module ‘@microsoft/sp-build-web’
Another important thing you can check which version of NodeJS you have installed, It should be Install NodeJS v8.11.4. This is the version which is supported. Do not install the latest version of NodeJS unless communicated from SPFx team.
If the issue still did not resolve, you can try the below solution which was suggested by Prabhu.
Run the below command:
npm i
Another solution you can try, run the below command:
npm install --save-dev
or
npm install --save
The difference between –save and –save-dev is, –save-dev is used to save the package for development purposes only, and –save is used to save the package for the application.
If the above solution does not work, you can try the below command.
To resolve Error: Cannot find module ‘@microsoft/sp-build-web’, you can also try the solution below.
npm install --save-dev '@microsoft/sp-build-web'
Once run the command, you can delete your existing old web part folder and recreate everything using Yeoman.
I hope now you will be able to fix the error cannot find module ‘@microsoft/sp-build-web’ in SharePoint Framework.
You may also like:
- Display SharePoint list items using SPFx
- How to Configure Web Part Icon in SPFx
- SharePoint Framework CRUD Operations using React
- [spfx-serve] The api entry could not be loaded: node_modules/@microsoft/sp-webpart-workbench/lib/api/ in SharePoint Framework
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 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
Thank you so much, it saved my day!