Error "Cannot find module 'react' or its corresponding type declarations." inside our sharePoint online SPFx project

john john 1,021 Reputation points
2022-06-05T14:23:31.303+00:00

I am working on an 1.14 SPFX web part, but inside the .ts file we are getting reference errors on almost all the libraries as shown in this picture:-

For example, on the first reference error "Cannot find module 'react' or its corresponding type declarations... i tried those commands:-

npm install react  
  
npm install --save-dev @types/react  
  
npm i @microsoft/rush-stack-compiler-3.9  

but did not fix anything.. any advice on this please?

Thanks

Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office SharePoint Server Development
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,251 Reputation points
    2022-06-06T06:30:00.537+00:00

    Hi @john john ,

    According to my research and testing, please try to set moduleResolution to node in your tsconfig.json file.

    208597-image.png
    If the error is not resolved, try to delete your node_modules and package-lock.json files, re-run npm install and restart your IDE. You can run the following command:

    rm -rf node_modules package-lock.json  
      
    npm install  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.