1

I am creating a SPFx web part which is using fs module, but getting error Error: Can't resolve 'fs'. I know this issue causing from typescript because of missing typings. Following is the exact error what my web part is displaying

***ERROR MESSAGE:

***Failed to load component "79bb3b95-9a04-44d5-8c56-6a8f6c93cf45" (SaketaIntranetManagerWebPart).

Original error: ***Failed to load entry point from component "79bb3b95-9a04-44d5-8c56-6a8f6c93cf22" (HelloWorld).

Original error: Error loading https://component-id.invalid/79bb3b95-9a04-44d5-8c56-6a8f6c93cf22_0.0.1 Cannot find module "fs"

***CALLSTACK:

_loadComponentImpl/<@https://localhost:4321/node_modules/@microsoft/sp-loader/dist/sp-loader_en-us.js:16232:21

I also tried running this command typings install dt~node --global --save but getting duplicate identifier issue after that. How to resolve this issue?

4
  • can you try it as npm install --save @types/node ? Jun 29, 2017 at 10:17
  • Still the same error. Module not found: Error: Can't resolve 'fs' Jun 29, 2017 at 10:59
  • I checked my solution is having node package inside @types folder. Jun 29, 2017 at 11:00
  • I have two problems: First why do I need 50 reputation to comment but i can do normal posts? Aren't comments more like a discussion and normal posts like "answers"? Wouldnt it be better to have reputation for normal posts excpet if you are the one writing the first article? Well all this doenst matter here so I come back to the topic with my second problem. While the above answer is true, in normal webpack config u could do something like this: node: { fs: 'empty' }, But i can't find any file thats matches this description: github.com/react-boilerplate/react-boilerplate/issues/2279#iss
    – shibo
    Nov 13, 2019 at 5:24

1 Answer 1

2

The fs module is a part of Node.js and is not available inside web parts. You could use it in custom Gulp tasks but not inside web parts. On runtime web parts run in web browser and not on top of the Node.js runtime which would explain the error that you're getting.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.